William Alex William Alex - 5 months ago 522x
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.


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() {