正在定义属性在单例类中为变量合成? [英] Is defining a property & synthesize for a variable in a singleton class allowed?

查看:46
本文介绍了正在定义属性在单例类中为变量合成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

定义属性&可以为单例类中的变量合成吗?如下所示在界面中,

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

@property(nonatomic,assign)NSInteger value;

和实施文件中

@synthesize value;

或者我们只需要声明一个如下变量,

or we just have to declare a variable like below,

@interface SingletonDataClass : NSObject
{
    NSInteger value;
}

推荐答案

您可以对常规类进行的任何操作都可以对单例进行处理.

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

没有称为单身"的语言概念,它只是常规Objective C类的常见用法.使类成为单例的原因是确保其实例化仅发生一次(即您自己的支持代码)的方式.

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.

这篇关于正在定义属性在单例类中为变量合成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆