3 ms·
A lot of the newer JVM languages provide better equivalents to Obj-C categories. Most of them also let you mix in instance variables along with methods. Check o
by cageface 14y ago
A lot of the newer JVM languages provide better equivalents to Obj-C categories. Most of them also let you mix in instance variables along with methods. Check out Scala or Kotlin for specific examples.
- mpweiher 14y agoObjective-C categories nowadays can include instance variables :-)
- cageface 14y agoReally? 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.
- mpweiher 14y agoMy 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+mid:b5aqssv3iowcsw2i+state:results 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+mid:pb57oyiiyp3vfomn+state:results http://markmail.org/message/yourm4nkghaf3bak#query:+page:1+m... (Checked on 10.8, instance-size for CF objects still incorrect)