Before upgrading to Swift 3, I had the following code:
//Set up singleton object for the tracker class func setup(tid: String) -> WatchGATracker { struct Static { static var onceToken: dispatch_once_t = 0 } dispatch_once(&Static.onceToken) { _analyticsTracker = WatchGATracker(tid: tid) } return _analyticsTracker }
I get the following error:
'dispatch_once_t' is unavailable in Swift: Use lazily initialized globals instead
Apparently, the conversion tool converted the code into this:
class func setup(_ tid: String) -> WatchGATracker { struct Static { static var onceToken: Int = 0 } _ = WatchGATracker.__once return _analyticsTracker }
And at the top of my class, he added the following:
private static var __once: () = { _analyticsTracker = WatchGATracker(tid: tid) }()
But I still get the error message:
Instance member 'tid' cannot be used on type 'WatchGATracker'
tid is declared as:
fileprivate var tid: String
It was declared as:
private var tid: String
I can't figure out how to fix my code, does anyone have any suggestions?
ios xcode swift swift3 watchkit
iOShepherd Sep 19 '16 at 15:29 2016-09-19 15:29
source share