Objective-c,.h中的方法声明和.m混淆中的私有属性

时间:2017-11-13 11:42:49

标签: ios objective-c methods properties private

我正在阅读this教程,其中他在cell .h file中声明了一个方法,该方法接受block实施{{1}中的方法他声明.m classprivate property method

同名 这是什么做法?只在.h中声明一个方法并在.m

中创建一个私有属性

我试着像这样做

我在.h文件中创建了一个方法

@property (copy, nonatomic) void (^didTapButtonBlock)(id sender);
<。>文件中的

-(void)xyz:(NSString*)string;

但Xcode发出警告@property (nonatomic, strong) NSString *string;

请告诉现场背后的情况?

1 个答案:

答案 0 :(得分:3)

他暴露了block变量的setter方法,但保持getter私有,如果你注意到,该方法有单词set,这是属性的setter方法

您可以这样做:

-(void)setXyz:(NSString*)xyz;

和.m:

@property (nonatomic, strong) NSString *xyz;

这种方法是确保其他类无法获取属性实例,但可以赋予它值