iOS ARC下命名规则
来源:互联网 发布:淘宝网男装阿迪达斯 编辑:程序博客网 时间:2024/05/12 08:42
当我在ARC模式下写以下代码的时候,编译器报错
Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects
@interface ViewController : UIViewController {
NSString *newTitle;
}
@property (strong, nonatomic) NSString *newTitle;
.m
@synthesize newTitle;
这是因为在高版本编译器ARC模式下,这种命名规范是不合理的,可以查看苹果官网的内存管理方面的文档中有说明the memory management rules
You take ownership of an object if you create it using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy”.
前面带有 new 的属性在@synthesize的时候会生成getter和setter方法,如果有new打头的属性的时候,在生成getter就会调用newTitle方法,编译器认为这是生成
新的对象,而不是get原有的属性,所以就提示错误信息。
解决办法:
1。new前加上别的字符例如theNewTitle
@property (strong, nonatomic) NSString *theNewTitle;
2。重写getter方法@property (strong, nonatomic, getter=theNewTitle) NSString *newTitle;
3。第三种是可以new开头,但是要告诉编译器不是new个新对象#ifndef __has_attribute
#define __has_attribute(x) 0 // Compatibility with non-clang compilers
#endif
#if __has_attribute(objc_method_family)
#define BV_OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
#else
#define BV_OBJC_METHOD_FAMILY_NONE
#endif
@interface ViewController : UIViewController@property (strong, nonatomic) NSString *newTitle;- (NSString *)newTitle BV_OBJC_METHOD_FAMILY_NONE;@end
4。这种也可以啊@synthesize newTitle = _newTitle; // Use instance variable _newTitle for storage
苹果已经有文档Transitioning to ARC Release Notes说明了开发者在命名的时候避免以 new 和 copy 开头
Unacceptable Object Names
- newButton
- newLabel
- newTitle
Acceptable Object Names
- _newButton
- mewLabel
- neueTitle
#arc #auto-synthesized #xcode-4.6.1
- iOS ARC下命名规则
- iOS中的ARC---ARC规则
- Cisco IOS 命名规则
- CISCO IOS命名规则
- IOS开发-命名规则
- iOS 图片命名规则
- iOS 工程命名规则
- Cisco IOS命名规则-历史
- 思科IOS软件命名规则
- ios启动页命名规则
- iOS编码规范、命名规则
- iOS应用图片命名规则
- 【IOS学习】之六、ARC规则
- iOS学习之——ARC规则
- Windows XP启动管理器boot.ini中的ARC命名规则
- 因为arc的命名规则而产生的一些错误
- ARC 下须遵守的规则详解
- Java下Android 命名规则
- 1069:判断三角形形状
- asp.net mvc中应用缓存依赖文件(xml)的一个小demo
- 日期格式化{0:yyyy-MM-dd HH:mm:ss.fff}和{0:yyyy-MM-dd hh:mm:ss.fff}的区别
- 高通msm8x60 boot(lk)的usb处理解析流程
- Redis与Memcached的区别
- iOS ARC下命名规则
- java中三大框架struts/Hibernate/Spring,具体是怎样合作工作的?各自实现什么功能?
- 1068:计算并集
- Firefox浏览器访问非80端口受限的解决方法
- MSM8260 EHCI-MSM72k主控制器的状态机迁移分析
- 简单抓取豆瓣电影
- Apache Thrift - 可伸缩的跨语言服务开发框架
- android——BaseAdapter使用
- HDU2719-字符串处理