Objective-C 类型
1. Strings
1) 简单字符串
NSString *aString = @"this is a string"; NSString *anotherString = @"and this is another one";
2) 对象初始化
NSString *aString = [[NSString alloc] initWithString:@"some string literal"]; NSString *aString = [NSString stringWithString:@"some string literal"];
3) 格式化字符串
int theValueOfPi = 3; //produces the string "pi is exactly 3!" NSString *aString = [NSString stringWithFormat:@"pi is exactly %d!", theValueOfPi];
4) 对象格式化
NSString *aString = @"criminals"; NSString *anotherString = [NSString stringWithFormat:@"When you %@ strings, only %@ will use strings.", @"criminalize", aString];
5) 字符串比较
NSString *aString = @"hello"; NSString *anotherString = @"hello"; BOOL stringsAreEqual = ([aString isEqualToString:anotherString]);
BOOL stringsAreEqual = (aString == anotherString); //这是错误的
技术改变世界