NSString in Objective-C
@"" literals are objects; messages do all the work.
#import <Foundation/Foundation.h>
int main(void) {
@autoreleasepool {
// @"" literals are NSString objects; messages do the work.
NSString *artist = @"Alice Coltrane";
NSString *label = [NSString stringWithFormat:@"%@ -- %d press",
artist, 1971];
NSLog(@"%@", label);
NSLog(@"Length: %lu", (unsigned long)[label length]);
NSLog(@"Shout: %@", [artist uppercaseString]);
NSLog(@"Match? %d", [artist isEqualToString:@"Alice Coltrane"]);
}
return 0;
}
How it works
stringWithFormat:is the printf of object creation.lengthanduppercaseStringare messages, not properties.isEqualToString:compares contents; == would compare pointers.
Keywords and builtins used here
NSStringintlongmainreturnunsignedvoid
The run, in numbers
- Lines
- 16
- Characters to type
- 449
- Tokens
- 96
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 89 seconds.
Step 3 of 3 in Values, step 3 of 27 in Language basics.