I made a Swift framework called SharedLocation with a Swift singleton class "SharedLocationManager" inside of it like so:
public class SharedLocationManager: CLLocationManager, CLLocationManagerDelegate
{
public class var sharedInstance: SharedLocationManager {
struct Static
{
static var onceToken : dispatch_once_t = 0
static var instance : SharedLocationManager? = nil
}
dispatch_once(&Static.onceToken)
{
Static.instance = SharedLocationManager()
}
return Static.instance!
}
public override init()
{
//do init stuff
}
A shared instance of this class should be accessable from my iOS app (written in Objective-C) and my WatchKit Extension (written in Swift).
i imported the framework in the iOS ViewController like so:
@import SharedLocation
and in the Watch InterfaceController like so:
import SharedLocation
I am able to get an instance of the singleton class in both targets BUT these are different instances (init() is called twice). When I access the sharedInstance inside the WatchKit Target everything works fine and I get the same instance every time.
Is it even possible to have a singleton class with multiple targets?