Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I have a category on UIView (because there are multiple UIViews of different classes that I want having the same property), and all the category does is define a property in the .h file.
And, as it turns out, that's exactly why I'm having an error.
 
Without code it is almost impossible to understand why you are getting and error.

Basically the reason is you are trying to send something which has not been initialized in some way.

You can declare something in the .h file but unless it is initialized in some manner in the code it is a nil object.

So did you answer your own question? "...that's exactly why I'm having an error."
 
Without code it is almost impossible to understand why you are getting and error.

Basically the reason is you are trying to send something which has not been initialized in some way.

You can declare something in the .h file but unless it is initialized in some manner in the code it is a nil object.

So did you answer your own question? "...that's exactly why I'm having an error."
Yes. You see, each category property must be implemented in the category's .m file. You can create a getter/setter, or you can use the "@dynamic" directive.
 
Is this really resolved? You can't directly add properties to classes through a catagory, you need to be using associated objects if that is the case. This is a limitation of the Objective-C runtime - I can find you more information if you'd like.

Adding @dynamic doesn't somehow allow the runtime to store the reference on the instance for you - it merely states that the setter and better are defined outside the superclass class, which in this case is the category. Because of that, the property was never synthesized and it's not a part of your instance. It's up to you to write the appropriate setter and getter using associated objects to set and retrieve that property from the Obj-C runtime.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.