NSArray in Objective-C
@[] builds an array; subscripts and messages read it.
#import <Foundation/Foundation.h>
int main(void) {
@autoreleasepool {
// @[] builds an NSArray; subscripts read it.
NSArray<NSString *> *bins = @[ @"jazz", @"soul", @"dub" ];
NSLog(@"%lu bins, first is %@",
(unsigned long)[bins count], bins[0]);
NSLog(@"Last: %@", [bins lastObject]);
NSLog(@"Has funk? %d", [bins containsObject:@"funk"]);
NSLog(@"All: %@", [bins componentsJoinedByString:@" / "]);
}
return 0;
}
How it works
@[ @"jazz", @"soul" ]is the literal form.bins[0]subscripts;countandlastObjectare messages.componentsJoinedByString:renders the whole array.
Keywords and builtins used here
NSArrayNSStringintlongmainreturnunsignedvoid
The run, in numbers
- Lines
- 15
- Characters to type
- 414
- Tokens
- 105
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 97 seconds.
Step 1 of 3 in Collections, step 10 of 27 in Language basics.