Reputation: 6030
I have following crash with sharedInstance
return Static.instance!
line:
EXC_BREAKPOINT 0x0000000100da42d8
Crash happened in Ad Hoc release build where there is no debug breakpoints.
According to call stack of the crash sharedInstance
should already exist at the time of crash (it is first called on app launch, crash occurred on button tap).
Crash occurred on iPad Air 2 with iOS 8.4.0, build is compiled with Swift 2.1 compiler in Xcode 7.1.1
App itself (which calls sharedInstance on launch) and DataSource class are located in different modules. Could it be that for classes from framework with DataSource class static struct is different?
@objc public final class DataSource : NSObject
{
public class var sharedInstance: DataSource
{
struct Static
{
static var instance: DataSource?
static var token: dispatch_once_t = 0
}
dispatch_once(&Static.token)
{() -> Void in
Static.instance = DataSource()
}
return Static.instance!
}
override init()
{
super.init()
...
}
...
}
Upvotes: 0
Views: 1247
Reputation: 285240
A static singleton is backed by GCD anyway so this is the recommended syntax
@objc public final class DataSource : NSObject
{
class var sharedInstance : DataSource {
struct Static {
static let sharedInstance = DataSource()
}
return Static.sharedInstance
}
override init()
{
super.init()
...
}
...
}
Upvotes: 1