向数组中添加一个值类型
//Objective-C
NSMutableArray *array = [NSMutableArray new];
//
[array addObject:[NSValue valueWithRect:CGRectMake(0, 0, 32, 64)]];
//在添加到集合前,值类型有对应的引用类型
//Swift
var array = [CGRect]()
//
array.append(CGRect(x: 0, y: 0, width: 32, height: 64))
创建一个字典
//Objective-C
NSDictionary *houseNumbers = @{ @"Paul": @7, @"Jess": @56, @"Peter": @332 };
//Swift
let houseNumbers = ["Paul": 7, "Jess": 56, "Peter": 332]
定义一个枚举
//Objective-C
typedef NS_ENUM(NSInteger, ShapeType) {
kCircle,
kRectangle,
kHexagon
};
//Swift
enum ShapeType: Int {
case circle
case rectangle
case hexagon
}
附加一串字符
//Objective-C
NSString *first = @"Hello, ";
NSString *second = [first stringByAppendingString:@" world!"];
//Swift
let first = "Hello, "
let second = first + "world!"
增加数字
//Objective-C
NSInteger rating = 4;
rating++;
rating += 3;
//Swift
var rating = 4
rating += 1
rating += 3
插入字符串
//Objective-C
NSString *account = @"twostraws";
NSString *str = [NSString stringWithFormat:@"Follow me on Twitter: %@", account];
//Swift
let account = "twostraws"
let str = "Follow me on Twitter: (account)"
打印调试信息
//Objective-C
NSString *username = @"twostraws";
NSLog(@"Username is %@", username);








