关于属性synthesize警告⚠️
来源:互联网 发布:linux vsftpd使用 编辑:程序博客网 时间:2024/06/06 02:11
问题:我在创建一个UICollectionViewController的时候,又定义了一个叫collectionView的UICollectionView类型的属性,这时候,系统会给出这样的⚠️:
Auto property synthesis will not synthesize property 'collectionView'; it will be implemented by its superclass, use @dynamic to acknowledge intention
原因分析:因为对于UICollectionViewController的UICollectionView属性,已经被synthesize了,这时候LLVM会创建这个属性的setter和getter方法。
重新inherit一个UICollectionViewController后,这个collectionView当然被继承下来了,这个时候我们在子类中再一次定义的collectionView属性跟父类继承下来的那个是不一样的两个。所以在编译的时候,LLVM判断不了这个collectionView是哪一个,需要执行那个setter和getter方法,才报了这个错误。
解决办法:可以重新命名子类的这个UICollectionView属性;或者在子类的实现文件的@implement AB下用@dynamic修饰符声明即可
@dynamic collectionView;
顺便说说@synthesize和@dynamic这两个修饰property的修饰符的区别。
总的来说这两个修饰符都是LLVM对代码的一种优化。在现在版本的Xcode会缺省@synthesize,也就是说声明一个property之后,LLVM会自动对property加上@synthesize,这时候LLVM会生成这个property的setter和getter方法实现。如果使用@dynamic修饰符,LLVM就不会生成相应的setter和getter方法的实现。需要我们自己重写。
- 关于属性synthesize警告⚠️
- iOS中关于属性@property和@synthesize的问题:
- Oc属性 @property @synthesize
- 关于@property和@synthesize
- 属性, 变量,@property,@synthesize,@dynamic
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- 关于@property&@synthesize使用详解
- 关于@property和@ synthesize梳理
- 关于@synthesize 和 @dynamic 关键字
- ios-关于@property和@synthesize
- 聊聊属性的隐藏@property和@synthesize
- HDU
- 房卡麻将分析系列之"千里传音"
- /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found错误的解决
- 【2017满分】尔雅 刘忠良 绿色康复答案题库
- LeetCode:169. Majority Element
- 关于属性synthesize警告⚠️
- [iOS]NSString到底使用Copy还是使用Strong属性,有什么区别
- java getclass()函数
- 记录开始的第一步
- Android传感器
- Python基本语法_变量作用域
- 第一个Java程序-自我介绍+反编译
- Python API:openstack
- 关于Struts的相关配置