Hacker News new | past | comments | ask | show | jobs | submit login

Objective-C categories nowadays can include instance variables :-)



Really? Since when? Do you have a link to docs? I've seen some hacks involving associated references but it was my understanding that categories were not allowed to add instance variables because Apple would have to make member access much slower to allow that kind of extension.


My bad: they are allowed in class extensions, which are similar to but not the same as categories.

Given how the new non-fragile ivars are implemented, it should be possible to add ivars anytime before the first instance is created (so load time should be OK), but that has apparently not been implemented, class extensions only work for code compiled together.

So I guess no dice, apart from associated objects or the old indexed-instance-variable tricks:

http://markmail.org/message/b5aqssv3iowcsw2i#query:+page:1+m...

Alas, those tricks break on bridged CF classes that have incorrect metadata:

http://markmail.org/message/yourm4nkghaf3bak#query:+page:1+m...

(Checked on 10.8, instance-size for CF objects still incorrect)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: