Is defining a property & synthesize for a variable

2019-08-30 05:31发布

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条回答
我命由我不由天
2楼-- · 2019-08-30 05:50

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.

查看更多
登录 后发表回答