William Alex William Alex - 2 years ago 1328
Swift Question

iOS Swift : EXC_BAD_ACCESS(code=EXC_i386_GPFLT ) regarding a singleton

My iOS app is returning this error.


This is occuring on
return Singleton.instance
Here is the code regarding the singleton I am using.

class var sharedData : SharedData {
struct Singleton {
static let instance = SharedData()

return Singleton.instance

Can someone help me understand this error and help me resolve it? Any suggestions or tips are appreciated it.

Answer Source

With Swift 1.2 there is an easier option to create singletons now:

class DataManager {
    static let sharedInstance = DataManager()

    /// To deny direct access, make your init function private if you want
    private init() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download