@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);
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值