@@ -50,109 +50,6 @@ open class OptimizelyManager: NSObject {
50
50
}
51
51
}
52
52
53
- @available ( swift, obsoleted: 1.0 )
54
- @objc ( notificationCenter) public var objc_notificationCenter : Objc_OPTNotificationCenter {
55
- class ObjcCenter : Objc_OPTNotificationCenter {
56
- var notifications : OPTNotificationCenter
57
-
58
- init ( notificationCenter: OPTNotificationCenter ) {
59
- notifications = notificationCenter
60
- }
61
-
62
- func addActivateNotificationListener( activateListener: @escaping ( [ String : Any ] , String , [ String : Any ] ? , [ String : Any ] , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
63
-
64
- let num = notifications. addActivateNotificationListener { ( experiment, userId, attributes, variation, event) in
65
-
66
- let attrs = attributes? . mapValues ( { ( val) -> Any in
67
- if let val = val {
68
- return val
69
- }
70
- else {
71
- return NSNull ( )
72
- }
73
- } )
74
- activateListener ( experiment, userId, attrs, variation, event)
75
- }
76
-
77
- if let num = num {
78
- return NSNumber ( value: num)
79
- }
80
-
81
- return nil
82
- }
83
-
84
- func addTrackNotificationListener( trackListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
85
- let num = notifications. addTrackNotificationListener { ( eventKey, userId, attributes, eventTags, event) in
86
-
87
- let attrs = attributes? . mapValues ( { ( val) -> Any in
88
- if let val = val {
89
- return val
90
- }
91
- else {
92
- return NSNull ( )
93
- }
94
- } )
95
-
96
- trackListener ( eventKey, userId, attrs, eventTags, event)
97
-
98
- }
99
-
100
- if let num = num {
101
- return NSNumber ( value: num)
102
- }
103
-
104
- return nil
105
- }
106
-
107
- func addDecisionNotificationListener( decisionListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
108
-
109
- let num = notifications. addDecisionNotificationListener { ( type, userId, attributes, decisionInfo) in
110
- let attrs = attributes? . mapValues ( { ( val) -> Any in
111
- if let val = val {
112
- return val
113
- }
114
- else {
115
- return NSNull ( )
116
- }
117
- } )
118
- decisionListener ( type, userId, attrs, decisionInfo)
119
- }
120
- if let num = num {
121
- return NSNumber ( value: num)
122
- }
123
-
124
- return nil
125
- }
126
-
127
- func addDatafileChangeNotificationListener( datafileListener: @escaping ( Data ) -> Void ) -> NSNumber ? {
128
- let num = notifications. addDatafileChangeNotificationListener { ( data) in
129
- datafileListener ( data)
130
- }
131
- if let num = num {
132
- return NSNumber ( value: num)
133
- }
134
-
135
- return nil
136
- }
137
-
138
- func removeNotificationListener( notificationId: Int ) {
139
- notifications. removeNotificationListener ( notificationId: notificationId)
140
- }
141
-
142
- func clearNotificationListeners( type: NotificationType ) {
143
- notifications. clearNotificationListeners ( type: type)
144
- }
145
-
146
- func clearAllNotificationListeners( ) {
147
- notifications. clearAllNotificationListeners ( )
148
- }
149
-
150
-
151
- }
152
-
153
- return ObjcCenter ( notificationCenter: self . notificationCenter)
154
- }
155
-
156
53
private let reInitLock = Dispatch . DispatchSemaphore ( value: 1 )
157
54
158
55
// MARK: - Public interfaces
@@ -782,8 +679,9 @@ open class OptimizelyManager: NSObject {
782
679
}
783
680
784
681
// MARK: - Objective-C Wrappers (WIP)
682
+ @available ( swift, obsoleted: 1.0 )
785
683
extension OptimizelyManager {
786
-
684
+ @ available ( swift , obsoleted : 1.0 )
787
685
@objc public convenience init ( sdkKey: String ) {
788
686
self . init ( sdkKey: sdkKey,
789
687
logger: nil ,
@@ -799,7 +697,7 @@ extension OptimizelyManager {
799
697
// eventDispatcher:OPTEventDispatcher?,
800
698
// userProfileService:OPTUserProfileService?,
801
699
// periodicDownloadInterval:Int? = nil) {
802
-
700
+ @ available ( swift , obsoleted : 1.0 )
803
701
@objc public func initializeSDK( completion: ( ( NSError ? , Data ? ) -> Void ) ? ) {
804
702
initializeSDK { result in
805
703
switch result {
@@ -812,30 +710,135 @@ extension OptimizelyManager {
812
710
813
711
}
814
712
}
815
-
713
+ @ available ( swift , obsoleted : 1.0 )
816
714
@objc public func initializeSDKWith( datafile: String ) throws {
817
715
try self . initializeSDK ( datafile: datafile)
818
716
}
819
-
717
+ @ available ( swift , obsoleted : 1.0 )
820
718
@objc public func activate( experimentKey: String ,
821
719
userId: String ,
822
720
attributes: [ String : Any ] ? ) throws -> String {
823
721
return try self . activate ( experimentKey: experimentKey, userId: userId, attributes: attributes as OptimizelyAttributes ? )
824
722
}
825
-
723
+ @ available ( swift , obsoleted : 1.0 )
826
724
@objc public func activate( experimentKey: String ,
827
725
userId: String ) throws -> String {
828
726
return try self . activate ( experimentKey: experimentKey, userId: userId, attributes: nil )
829
727
}
830
728
831
-
729
+ @ available ( swift , obsoleted : 1.0 )
832
730
@objc public func trackWith( eventKey: String ,
833
731
userId: String ,
834
732
attributes: [ String : Any ] ? ,
835
733
eventTags: [ String : Any ] ? ) throws {
836
734
try self . track ( eventKey: eventKey, userId: userId, attributes: attributes, eventTags: eventTags)
837
735
}
838
736
737
+ @available ( swift, obsoleted: 1.0 )
738
+ @objc ( notificationCenter) public var objc_notificationCenter : Objc_OPTNotificationCenter {
739
+ class ObjcCenter : Objc_OPTNotificationCenter {
740
+ var notifications : OPTNotificationCenter
741
+
742
+ init ( notificationCenter: OPTNotificationCenter ) {
743
+ notifications = notificationCenter
744
+ }
745
+
746
+ func addActivateNotificationListener( activateListener: @escaping ( [ String : Any ] , String , [ String : Any ] ? , [ String : Any ] , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
747
+
748
+ let num = notifications. addActivateNotificationListener { ( experiment, userId, attributes, variation, event) in
749
+
750
+ let attrs = attributes? . mapValues ( { ( val) -> Any in
751
+ if let val = val {
752
+ return val
753
+ }
754
+ else {
755
+ return NSNull ( )
756
+ }
757
+ } )
758
+ activateListener ( experiment, userId, attrs, variation, event)
759
+ }
760
+
761
+ if let num = num {
762
+ return NSNumber ( value: num)
763
+ }
764
+
765
+ return nil
766
+ }
767
+
768
+ func addTrackNotificationListener( trackListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
769
+ let num = notifications. addTrackNotificationListener { ( eventKey, userId, attributes, eventTags, event) in
770
+
771
+ let attrs = attributes? . mapValues ( { ( val) -> Any in
772
+ if let val = val {
773
+ return val
774
+ }
775
+ else {
776
+ return NSNull ( )
777
+ }
778
+ } )
779
+
780
+ trackListener ( eventKey, userId, attrs, eventTags, event)
781
+
782
+ }
783
+
784
+ if let num = num {
785
+ return NSNumber ( value: num)
786
+ }
787
+
788
+ return nil
789
+ }
790
+
791
+ func addDecisionNotificationListener( decisionListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
792
+
793
+ let num = notifications. addDecisionNotificationListener { ( type, userId, attributes, decisionInfo) in
794
+ let attrs = attributes? . mapValues ( { ( val) -> Any in
795
+ if let val = val {
796
+ return val
797
+ }
798
+ else {
799
+ return NSNull ( )
800
+ }
801
+ } )
802
+ decisionListener ( type, userId, attrs, decisionInfo)
803
+ }
804
+ if let num = num {
805
+ return NSNumber ( value: num)
806
+ }
807
+
808
+ return nil
809
+ }
810
+
811
+ func addDatafileChangeNotificationListener( datafileListener: @escaping ( Data ) -> Void ) -> NSNumber ? {
812
+ let num = notifications. addDatafileChangeNotificationListener { ( data) in
813
+ datafileListener ( data)
814
+ }
815
+ if let num = num {
816
+ return NSNumber ( value: num)
817
+ }
818
+
819
+ return nil
820
+ }
821
+
822
+ func removeNotificationListener( notificationId: Int ) {
823
+ notifications. removeNotificationListener ( notificationId: notificationId)
824
+ }
825
+
826
+ func clearNotificationListeners( type: NotificationType ) {
827
+ notifications. clearNotificationListeners ( type: type)
828
+ }
829
+
830
+ func clearAllNotificationListeners( ) {
831
+ notifications. clearAllNotificationListeners ( )
832
+ }
833
+
834
+
835
+ }
836
+
837
+ return ObjcCenter ( notificationCenter: self . notificationCenter)
838
+ }
839
+
840
+
841
+
839
842
func convertErrorForObjc( _ error: Error ) -> NSError {
840
843
var errorInObjc : NSError
841
844
0 commit comments