@dynamic 跟@synthesize区别,@encode
@dynamic 和@synthesize区别,@encode?@dynamic 是相对于 @synthesize的,它们用样用于修饰 @property,用于
@dynamic 和@synthesize区别,@encode
?
@dynamic 是相对于 @synthesize的,它们用样用于修饰 @property,用于生成对应的的getter和setter方法。但是@?dynamic表示这个成员变量的getter和setter方法并不是直接由编译器生成,而是手工生成或者运行时生成。示例如下:@implementation ClassName
@synthesize aProperty,?bProperty;
@synthesize cProperty=instanceVariableName;
@dynamic anotherProperty;
// method implementations@end
@encode 是用于表示一个类型的字符串,对此,苹果有专门的介绍文档:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html?
示例代码如下:
-(void)?aMethod
{
? ??char?*enc1?=?@encode(int);?? ? ? ? ? ? ? ??
// enc1 = "i"? ??char?*enc2?=?@encode(id);?? ? ? ? ? ? ? ? ?
// enc2 = "@"? ??char?*enc3?=?@encode(@selector(aMethod));??
// enc3 = ":"? ??
// practical example:? ? CGRect rect?=?CGRectMake(0,?0,?100,?100);
? ? NSValue?*v?=?[NSValue value:&rect withObjCType:@encode(CGRect)];
}