我想創建一個真正的動態類,它具有屬性塊。 我想要的是使這個塊函數能夠訪問類實例變量和屬性。作爲屬性塊並訪問類實例變量
這裏的代碼與我的疑問:
/* 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?
}
所以從前面的代碼我的疑問是:如何從已存儲的對象本身的屬性塊直接訪問實例變量的對象。
是的!這是我正在尋找的。謝謝:) – MatterGoal
快樂服務! –
我不明白爲什麼捕獲'myClass'不應該工作。我可以忽略一些東西嗎 –