打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
IOS

一、SDK中描述是在声明property的时候,有2个选择
1:通过@synthesize 指令告诉编译器在编译期间产生getter/setter方法。
2:通过@dynamic指令,自己实现方法。
有些存取是在运行时动态创建的,如在CoreData的NSManagedObject类使用的某些。如果你想这些情况下,声明和使用属性,但要避免缺少方法在编译时的警告,你可以使用@dynamic动态指令,而不是@synthesize合成指令例如
@interface Demo : NSManagedObject {
}
@property (retain) NSString* test;
@end

@implementation Demo
@dynamic test;
@end

二、

@synthesize will generate getter and setter methods for your property. @dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass)

Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet:

Super class:

@property(nonatomic, retain)NSButton*someButton;
...
@synthesize someButton;

Subclass:

@property(nonatomic, retain)IBOutletNSButton*someButton;
...
@dynamic someButton;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
OC属性与实例变量
iOS中 @synthesize 和 @dynamic 区别
@property跟成员变量区别
@synthesize和@dynamic区别
关于@property及@synthesize以两Demo简单说明
Objective-C入门教程03:属性(@property和@synthesize)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服