@synthesize和@dynamic的区别是什么?

@synthesize和@dynamic的区别是什么?

//////////MutableArray ,delegate.
@synthesize 是系统自动生成getter和setter属性声明
@dynamic 是开发者自已提供相应的属性声明
@dynamic 意思是由开发人员提供相应的代码:对于只读属性需要提供 setter,对于读写属性需要提供 setter 和 getter。@synthesize 意思是,除非开发人员已经做了,否则由编译器生成相应的代码,以满足属性声明。

@dynamic 意思是由开发人员提供相应的代码:对于只读属性需要提供 setter,对于读写属性需要提供 setter 和 getter。
@synthesize 意思是,除非开发人员已经做了,否则由编译器生成相应的代码,以满足属性声明。

查阅了一些资料确定@dynamic的意思是告诉编译器,属性的获取与赋值方法由用户自己实现, 不自动生成。
@dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass)

#import "NSMutableArray+DaoXu.h"

@implementation NSMutableArray (DaoXu)
@dynamic name;
-(void)daoXu{
NSMutableArray *array=[NSMutableArray arrayWithObjects:@"zhang",@"ming",@"wei",nil];
unsigned long c=array.count;
for (int i=(int)c-1; i>=0; i--) {
NSLog(@"array==%@",[array objectAtIndex:i]);
}
NSLog(@"%lu,,",c);
}
@end


{

if(self.delegate && [self.delegate conformsToProtocol:@protocol(SalerProtocol) ])
{
[self.delegate saleSomthing:self.house];
}
else
{
NSLog(@"没人帮我卖:%@,我自己不想麻烦!",self.house);
}
}

猜你喜欢

转载自zhangmingwei.iteye.com/blog/1877211