我想创建一个真正动态的类,它具有一个块作为属性。我想要的是使这个块函数能够访问 Class 实例变量和属性。
这是我怀疑的代码:
/* MyClass Interface */
@interface MyClass:NSObject
@property (nonatomic, strong) NSString *variable;
@property (nonatomic, assign) void (^updateFunction)();
@end
/* MyClass implementation */
@implementation MyClass
-(void)update{
//Perform the block function code
self.updateFunction();
}
@end
/* MyClass usage*/
MyClass *myClass = [[MyClass alloc]init];
myClass.variable = @"Variable Value";
myClass.updateFunction = ^{
//HERE MY DOUBT...
//How can I access the myClass.variable and be sure that when this block
//will be called it didn't get a bad access?
}
因此,从前面的代码中,我的疑问是:如何直接从已存储为 Object 本身属性的块中访问 Object 的实例变量。