Skip to content

Commit 3837278

Browse files
hide objective-c methods from swift
1 parent ad45cac commit 3837278

File tree

1 file changed

+112
-109
lines changed

1 file changed

+112
-109
lines changed

OptimizelySDK/Optimizely/OptimizelyManager.swift

Lines changed: 112 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -50,109 +50,6 @@ open class OptimizelyManager: NSObject {
5050
}
5151
}
5252

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-
15653
private let reInitLock = Dispatch.DispatchSemaphore(value: 1)
15754

15855
// MARK: - Public interfaces
@@ -782,8 +679,9 @@ open class OptimizelyManager: NSObject {
782679
}
783680

784681
// MARK: - Objective-C Wrappers (WIP)
682+
@available(swift, obsoleted: 1.0)
785683
extension OptimizelyManager {
786-
684+
@available(swift, obsoleted: 1.0)
787685
@objc public convenience init(sdkKey: String) {
788686
self.init(sdkKey: sdkKey,
789687
logger: nil,
@@ -799,7 +697,7 @@ extension OptimizelyManager {
799697
// eventDispatcher:OPTEventDispatcher?,
800698
// userProfileService:OPTUserProfileService?,
801699
// periodicDownloadInterval:Int? = nil) {
802-
700+
@available(swift, obsoleted: 1.0)
803701
@objc public func initializeSDK(completion: ((NSError?, Data?) -> Void)?) {
804702
initializeSDK { result in
805703
switch result {
@@ -812,30 +710,135 @@ extension OptimizelyManager {
812710

813711
}
814712
}
815-
713+
@available(swift, obsoleted: 1.0)
816714
@objc public func initializeSDKWith(datafile:String) throws {
817715
try self.initializeSDK(datafile: datafile)
818716
}
819-
717+
@available(swift, obsoleted: 1.0)
820718
@objc public func activate(experimentKey: String,
821719
userId: String,
822720
attributes: [String:Any]?) throws -> String {
823721
return try self.activate(experimentKey: experimentKey, userId: userId, attributes: attributes as OptimizelyAttributes?)
824722
}
825-
723+
@available(swift, obsoleted: 1.0)
826724
@objc public func activate(experimentKey: String,
827725
userId: String) throws -> String {
828726
return try self.activate(experimentKey: experimentKey, userId: userId, attributes: nil)
829727
}
830728

831-
729+
@available(swift, obsoleted: 1.0)
832730
@objc public func trackWith(eventKey:String,
833731
userId: String,
834732
attributes: [String:Any]?,
835733
eventTags: [String:Any]?) throws {
836734
try self.track(eventKey: eventKey, userId: userId, attributes: attributes, eventTags: eventTags)
837735
}
838736

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+
839842
func convertErrorForObjc(_ error: Error) -> NSError {
840843
var errorInObjc: NSError
841844

0 commit comments

Comments
 (0)