Singleton pattern in objc, how to keep init private?

后端 未结 4 1147
说谎
说谎 2020-12-19 23:47

How can i make sure user do not call init, instead client should call sharedSingleton to get a shared instance.

@synthesize delegate;

- (id)init
{
    self          


        
4条回答
  •  有刺的猬
    2020-12-20 00:15

    Short answer: you can't; Objective-C has no concept of private methods.

    Check out the answer to this similar question.

提交回复
热议问题