Skip to content

Instantly share code, notes, and snippets.

@HFreni
Last active March 7, 2016 22:57
Show Gist options
  • Save HFreni/f31aafe746441bcb2e75 to your computer and use it in GitHub Desktop.
Save HFreni/f31aafe746441bcb2e75 to your computer and use it in GitHub Desktop.
Try Objective-C
NSLog(@"Harrison")
NSString *firstName = @"Harrison";
NSLog(firstName);
NSLog(@"Hello there, %@.", firstName);
NSLog(@"%@ %@", firstName, firstName);
NSString *lastName = @"Freni";
NSLog(@"%@ %@", firstName, lastName);
NSNumber *age = @16;
NSLog(@"%@ is %@ years old", firstName, age);
NSArray *apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot"];
NSLog(@"%@", apps[1]);
apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot", @"Instacanvas"];
NSDictionary *appRatings = @{@"AngryFowl": @3, @"Lettertouch": @5};
NSLog(@"Lettertouch has a rating of %@.", appRatings[@"Lettertouch"]);
//1
[tryobjc completeThisChallenge];
//2
NSArray *foods = @[@"tacos", @"burgers"];
NSLog(@"%@", [foods description]);
//3
NSArray *foods = @[@"tacos", @"burgers"];
NSString *result = [foods description];
NSLog(@"%@", result);
//4
NSString *city = @"Ice World";
NSUInteger cityLength = [city length];
NSLog(@"City has %lu characters", cityLength);
//5
NSNumber *higgiesAge = @6;
NSNumber *phoneLives = @3;
NSUInteger higgiesAgeInt = [higgiesAge unsignedIntegerValue];
NSUInteger phoneLivesInt = [phoneLives unsignedIntegerValue];
NSUInteger higgiesRealAge = higgiesAgeInt * phoneLivesInt;
NSLog(@"Higgie is actually %lu years old.", higgiesRealAge);
//6
NSString *firstName = @"Harrison";
NSString *lastName = @"Freni";
NSString *fullName = [firstName stringByAppendingString:lastName];
NSLog(@"%@", fullName);
//7
NSString *firstName = @"Harrison";
NSString *lastName = @"Freni";
NSString *fullName = [[firstName stringByAppendingString:@" "] stringByAppendingString:lastName];
NSLog(@"%@", fullName);
//8
NSString *firstName = @"Harrison";
NSString *lastName = @"Freni";
NSString *fullName = [[firstName stringByAppendingString:@" "] stringByAppendingString:lastName];
NSString *replaced = [fullName stringByReplacingOccurrencesOfString:firstName withString:lastName];
NSLog(@"%@", replaced);
//9
NSString *firstName = @"Harrison";
NSString *copy = [NSString stringWithString:firstName];
NSLog(@"%@ is a copy of %@", copy, firstName);
//10
NSString *firstName = @"Harrison";
NSString *copy = [[NSString alloc] initWithString:firstName];
NSLog(@"%@ is a copy of %@", copy, firstName);
//11
NSString *firstName = @"Harrison";
NSString *lastName = @"Freni";
NSString *fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
NSLog(@"%@", fullName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment