@@ -716,80 +716,58 @@ extension OptimizelyManager {
716
716
notifications = notificationCenter
717
717
}
718
718
719
+ internal func convertAttribues( attributes: OptimizelyAttributes ? ) -> [ String : Any ] ? {
720
+ return attributes? . mapValues ( { ( val) -> Any in
721
+ if let val = val {
722
+ return val
723
+ }
724
+ else {
725
+ return NSNull ( )
726
+ }
727
+ } )
728
+ }
729
+
730
+ internal func returnVal( num: Int ? ) -> NSNumber ? {
731
+ if let num = num {
732
+ return NSNumber ( value: num)
733
+ }
734
+
735
+ return nil
736
+ }
737
+
719
738
func addActivateNotificationListener( activateListener: @escaping ( [ String : Any ] , String , [ String : Any ] ? , [ String : Any ] , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
720
739
721
740
let num = notifications. addActivateNotificationListener { ( experiment, userId, attributes, variation, event) in
722
741
723
- let attrs = attributes? . mapValues ( { ( val) -> Any in
724
- if let val = val {
725
- return val
726
- }
727
- else {
728
- return NSNull ( )
729
- }
730
- } )
731
- activateListener ( experiment, userId, attrs, variation, event)
742
+ activateListener ( experiment, userId, self . convertAttribues ( attributes: attributes) , variation, event)
732
743
}
733
744
734
- if let num = num {
735
- return NSNumber ( value: num)
736
- }
737
-
738
- return nil
745
+ return returnVal ( num: num)
739
746
}
740
747
741
748
func addTrackNotificationListener( trackListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
742
749
let num = notifications. addTrackNotificationListener { ( eventKey, userId, attributes, eventTags, event) in
743
750
744
- let attrs = attributes? . mapValues ( { ( val) -> Any in
745
- if let val = val {
746
- return val
747
- }
748
- else {
749
- return NSNull ( )
750
- }
751
- } )
752
-
753
- trackListener ( eventKey, userId, attrs, eventTags, event)
754
-
755
- }
756
-
757
- if let num = num {
758
- return NSNumber ( value: num)
751
+ trackListener ( eventKey, userId, self . convertAttribues ( attributes: attributes) , eventTags, event)
759
752
}
760
753
761
- return nil
754
+ return returnVal ( num : num )
762
755
}
763
756
764
757
func addDecisionNotificationListener( decisionListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
765
758
766
759
let num = notifications. addDecisionNotificationListener { ( type, userId, attributes, decisionInfo) in
767
- let attrs = attributes? . mapValues ( { ( val) -> Any in
768
- if let val = val {
769
- return val
770
- }
771
- else {
772
- return NSNull ( )
773
- }
774
- } )
775
- decisionListener ( type, userId, attrs, decisionInfo)
760
+ decisionListener ( type, userId, self . convertAttribues ( attributes: attributes) , decisionInfo)
776
761
}
777
- if let num = num {
778
- return NSNumber ( value: num)
779
- }
780
-
781
- return nil
762
+ return returnVal ( num: num)
782
763
}
783
764
784
765
func addDatafileChangeNotificationListener( datafileListener: @escaping ( Data ) -> Void ) -> NSNumber ? {
785
766
let num = notifications. addDatafileChangeNotificationListener { ( data) in
786
767
datafileListener ( data)
787
768
}
788
- if let num = num {
789
- return NSNumber ( value: num)
790
- }
791
769
792
- return nil
770
+ return returnVal ( num : num )
793
771
}
794
772
795
773
func removeNotificationListener( notificationId: Int ) {
0 commit comments