Singleton in iOS Objective C doesn't prevent more than one instance

后端 未结 9 1557
长情又很酷
长情又很酷 2020-11-29 08:53

I know there are several threads on this, but none answer my questions.

I\'ve implemented my singleton class like this (being aware of the controversy about singleto

9条回答
  •  清酒与你
    2020-11-29 09:26

    This works for me:

    static AudioRecordingGraph * __strong sharedInstance;
    
    +(instancetype)sharedInstance {
    
        @synchronized(self) {
    
            if(!sharedInstance) {
    
                sharedInstance = [AudioRecordingGraph new];
            }
            return sharedInstance;
        }
    }
    

提交回复
热议问题