Hi, I'm solving the following problem. I have a huge array of items of the same class MyItem. All items need to share a certain global "context" variable. Normally, I would wrap access to this variable in a class-level (+) method of MyItem, like +[MyItem getContext].
Now the problem is that I need multiple arrays of MyItems have different contexts. The solution could be to add the context pointer as an ivar to each MyItem instance, but I would not like to waste memory on that (the arrays are huge). How do I solve this problem? I have an idea that I could spawn new subclasses of MyClass at run time, for each new array of MyItems, assigning each class with a different class-level context variable, and then instantiating items from that subclass. In this way, +[_runtime_subclass_of_MyItem getContext] would return a different context value for each array. This would reuse the "isa" pointer that's already in any NSObject instance. Is this possible in Obj-C? Or is there a better idea? Thanks! _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
