我指的是苹果的 Swift 编程指南,用 Swift 语言来理解可变/不可变对象(数组、字典、集合、数据)的创建。但是我不能理解如何在 Swift 中创建一个不可变的集合。
我希望在 Objective-C 中看到下面的 Swift 中的等价物
不可变数组
NSArray *imArray = [[NSArray alloc]initWithObjects:@"First",@"Second",@"Third",nil];
可变阵列
NSMutableArray *mArray = [[NSMutableArray alloc]initWithObjects:@"First",@"Second",@"Third",nil];
[mArray addObject:@"Fourth"];
永恒字典
NSDictionary *imDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Value1", @"Key1", @"Value2", @"Key2", nil];
可变字典
NSMutableDictionary *mDictionary = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Value1", @"Key1", @"Value2", @"Key2", nil];
[mDictionary setObject:@"Value3" forKey:@"Key3"];