I have built a category for NSDate and I would like to encapsulate an attribute in this category to hold some data. But I can’t achieve adding this attribute, only methods.
Is there any way to achieve this ?
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here some Code:
Filename: NSObject+dictionary.h
Filename: NSObject+dictionary.m
Now every instance (of every class) has a dictionary, where you can store your custom attributes.
With Key-Value Coding you can set a value like this:
And you can get the value like this:
That even works great with the Interface Builder and User Defined Runtime Attributes.