In PHP and in JavaScript you can dynamically use a variable by using another variable as part of its name. I do not want to use an array as part of the solution. Can this be achieved in Objective C? I'd like to do something like this:
for (int i=1; i<6; i++) {
if([appRecord.answer(i) length] != 0){
self.textView.answer(i)ViewSingle.text = appRecord.answer(i);
}
}
Short answer: No.
Long answer: Kind of.
IBOutlets
, then use an IBOutletCollection
instead.@property
, and then use [self valueForKey:]
to look them up by name.object_getInstanceVariable()
to retrieve it's value directly (this is similar to #3, except you don't have to declare it as an @property
). This is excessively complicated and is usually a much bigger hammer than you'll actually need.[superview viewWithTag:aTag]
. I do not recommend using this approach.EDIT: Note that this only works with instance variables. This does not work with global/static variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With