I want to create instance variables dynamically at runtime, and I want to add these variables to a category. The number of the instance variables may change based on the configuration/properties file which I am using for defining them.
Any ideas??
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.
I’d be inclined to just use a
NSMutableDictionary(see NSMutableDictionary Class Reference). Thus, you would have an ivar:You’d then initialize it:
You can then save values to it dynamically in code, e.g.:
Or, if you are reading from a file and don’t know what the names of the keys are going to be, you can do this programmatically, e.g.:
And if you’re using an older version of Xcode (before 4.5), the syntax is: