OBJECTIVE-C 基礎教學2/5 codeschool
Objects and Classes
[objectName messageName];
[tryobjc completeThisChallenge];
----------
NSArray *foods = @[@"tacos", @"burgers"];
NSLog(@"%@", foods);
NSArray *foods = @[@"tacos", @"burgers"];
NSString *result = [foods description];
NSLog(@"%@", result);
----------
NSString *city = @"Ice World";
NSUInteger cityLength = [city length];
NSLog(@"City has %lu characters", cityLength);
----------
NSNumber *higgiesAge = @6;
NSNumber *phoneLives = @3;
NSNumber *product = higgiesAge * phoneLives;
NSLog(@"Higgie is actually %@ years old.", product);
NSUInteger higgiesAgeInteger = [higgiesAge unsignedIntegerValue];
NSUInteger phoneLivesInt = [phoneLives unsignedIntegerValue];
NSUInteger higgiesRealAge = higgiesAgeInt * phoneLivesInt;
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);
----------
NSString *firstName = @"dairs";
NSString *lastName =@"jobs";
NSString *fullName = [firstName stringByAppendingString:lastName];
NSLog(@"%@", fullName);
NSString *string1 = @"iphone";
NSString *string2 = [[NSString alloc] initWithFormat:@"nice"];
string1 = [[string1 stringByAppendingString:@"is"] stringByAppendingString:string2];
NSLog(@"%@",string1);
NSString *firstName = @"dairs";
NSString *lastName =@"jobs";
NSString *fullName = [[firstName stringByAppendingString:@" "] stringByAppendingString:lastName];
NSLog(@"%@", fullName);
NSString *firstName = @"daris";
NSString *lastName =@"jobs";
NSString *fullName = [[firstName stringByAppendingString:@" "]
stringByAppendingString:lastName];
NSString *replaced = [fullName stringByReplacingOccurrencesOfString:firstName
withString:lastName];
NSLog(@"%@", replaced);
NSString *firstName = @"dairs";
NSString *copy = [NSString stringWithString:firstName];
NSLog(@"%@ is a copy of %@", copy, firstName);
NSString *firstName = @"dairs";
NSString *copy = [[NSString alloc] initWithString:firstName];
NSLog(@"%@ is a copy of %@", copy, firstName);
NSString *firstName = @"dairs";
NSString *lastName =@"jobs";
NSString *fullName = [NSString stringWithFormat:@"%@ %@",firstName,lastName];
NSLog(@"%@", fullName);
Comments
Post a Comment