M
M
mopsicus2014-06-27 11:45:08
iOS
mopsicus, 2014-06-27 11:45:08

How to properly initialize singleton in didFinishLaunchingWithOptions?

Hello, I can’t figure out what the problem is:
there is the most common singleton implementation:

+ (User *)current {
    static User *singleton = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        singleton = [[User alloc] init];
    });
    return singleton;
}

when called in didFinishLaunchingWithOptions, it hangs on dispatch_once (...)
if transferred to viewDidload, then everything is fine Tell me
what to change to make it work
Thank you

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
S
s0L, 2014-06-27
@mopsicus

Make sure that [[User alloc] init] does not call the same current method again, most likely you have a dead lock.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question