Sometimes, I get sad when I can't use Python. In Python, I handle an array of arguments, unpacking them as such:
name, handle, parent_handle, [left, top, right, bottom], showing, scrollable = data
I must now do the same in Objective-C, with NSArray
s. Am I doomed to 11 lines of:
NSString *name = (NSString *)[data objectAtIndex:0];
NSNumber *handle = (NSNumber *)[data objectAtIndex:1];
//....
or is there a better way?
Yes. You are doomed. DOOMED! Mwah ha ha ha ha!
You can omit the casts and use subscripting to make it a little bit shorter though:
NSString *name = data[0];
NSNumber *handle = data[1];
// ...
You can omit the casts because both objectAtIndex:
and subscripting return type id
, which can be converted to any Objective-C class type without casting.
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