开发者

Objective C concept explanation

开发者 https://www.devze.com 2022-12-13 17:07 出处:网络
I have the following code: - (void)setItem:(Todo *)newItem { item = newItem; } Why is it that I can\'t do

I have the following code: - (void)setItem:(Todo *)newItem { item = newItem; }

Why is it that I can't do - (void)setItem:(Todo *)newItem { self.item = newItem; } ?

I have item decla开发者_高级运维red in my header file but I get a EXC_BAD_ACCESS error? Item is also not synthesized. The method is meant to be a custom setter.

Thanks!


self.item = newItem; will cause an infinite loop since it's calling setItem.


'self.item' means 'the property called item', not the variable called item (unlike Java or C#). Just use 'item = newItem;'. And don't forget to retain it if necessary!

0

精彩评论

暂无评论...
验证码 换一张
取 消