初始化一个只读属性
来源:互联网 发布:淘宝贾真 编辑:程序博客网 时间:2024/05/01 21:59
Either assign to the instance variable directly (don't forget to add a retain
orcopy
if you need it) or redeclare the property in a private class extension. Like this:
In your .h file:
@property (readonly, copy) NSString *firstName;
In your .m file:
@interface MyClass ()// Redeclare property as readwrite@property (readwrite, copy) NSString *firstName;@end@implementation MyClass@synthesize firstName;...
Now you can use the synthesized setter in your implementation but the class interface still shows the property as readonly. Note that other classes that import your .h file can still call-[MyClass setFirstName:]
but they won't know that it exists and will get a compiler warninganother
In your .h file:
@property (readonly, copy)NSString*firstName;
@interface MyClass ()
@synthesize firstName = _firstName;
@end
only can you use _fisrtName to init
- 初始化一个只读属性
- WCF - 只读属性
- CEdit 字体大小 只读属性
- 关于只读属性
- combobox只读属性
- linux文件只读属性
- javascript对象只读属性
- 只读属性的赋值
- select 设置只读属性
- Text为只读属性
- c# 中的只读属性
- 文本框只读属性
- Untiy 只读属性实现
- Python 定义只读属性
- C#定义属性-只读属性
- 一个 只读 readonly 示例
- 一个支持只读属性的键/值对字符串处理类
- 怎么设置文本属性为只读和隐藏 C#里面采用FileSream写入一个txt文本
- 数据库设计范式的理解
- [Android实例] 【eoeAndroid社区索引】android网络通信之HTTP协议教程实例汇总
- 敏捷开发一千零一问系列之二十七:各自分工下如何扑克牌估算?
- ucosii任务堆栈的作用是什么呢?
- 嵌入式或linux测试
- 初始化一个只读属性
- 求二叉树中双分支结点的个数
- Android init进程中鲜为人知的charger mode 模式 .
- pig
- 修改win7本机的最大数据包大小
- 在Ubuntu下如何切换到超级用户
- Git 常用命令
- CSS3下147个颜色名称及对应颜色值【示例】
- [Leetcode]Anagram