Is defining a property & synthesize for a variable in a singleton class allowed?

谁都会走 提交于 2019-12-13 04:27:44

问题


Defining a property & synthesize for a variable in a singleton class allowed?,like below in interface,

@property(nonatomic,assign)NSInteger value;

and in implementation file,

@synthesize value;

or we just have to declare a variable like below,

@interface SingletonDataClass : NSObject
{
    NSInteger value;
}

回答1:


Anything that you can do with your regular classes you can do with singletons.

There is no language concept called "singleton", it is just a common usage pattern of regular Objective C classes. What makes a class a singleton is the way you ensure its instantiation happens only once, i.e. your own supporting code.



来源:https://stackoverflow.com/questions/11914219/is-defining-a-property-synthesize-for-a-variable-in-a-singleton-class-allowed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!