Objective-C equivalent to "unpacking tuples"

Sometimes I feel sad when I cannot use Python. In Python, I process an array of arguments, unpacking them as such:

name, handle, parent_handle, [left, top, right, bottom], showing, scrollable = data 

Now I have to do the same in Objective-C, with NSArray s. I am doomed to 11 lines:

 NSString *name = (NSString *)[data objectAtIndex:0]; NSNumber *handle = (NSNumber *)[data objectAtIndex:1]; //.... 

or is there a better way?

+8
objective-c
source share
1 answer

Yes. You are doomed. DOOMED! Mwa ha ha ha ha!

You can omit throws and use captions to make it a little shorter, though:

 NSString *name = data[0]; NSNumber *handle = data[1]; // ... 

You can omit throws because both types of objectAtIndex: and subscriptip return an id type that can be converted to any class of the Objective-C class without casting.

+12
source share

All Articles