我想在Objective-C中查看Swift中的以下内容
不可变数组
NSArray *imArray = [[NSArray alloc]initWithObjects:@"First",@"Second",@"Third",nil];
可变阵列
NSMutableArray *mArray = [[NSMutableArray alloc]initWithObjects:@"First",nil];[mArray addobject:@"Fourth"];
不变字典
NSDictionary *imDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Value1",@"Key1",@"Value2",@"Key2",nil];
可变字典
NSMutableDictionary *mDictionary = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Value1",nil];[mDictionary setobject:@"Value3" forKey:@"Key3"];数组
创建不可变数组
第一种方式:
let array = NSArray(array: ["First","Second","Third"])
第二种方式:
let array = ["First","Third"]
创建可变数组
var array = ["First","Third"]
将对象附加到数组
array.append("Forth")
词典
创建不可变字典
let dictionary = ["Item 1": "description","Item 2": "description"]
创建可变字典
var dictionary = ["Item 1": "description","Item 2": "description"]
将新对附加到字典
dictionary["Item 3"] = "description"
More information on Apple Developer
总结以上是内存溢出为你收集整理的在Swift中的ios – 不可变/可变集合全部内容,希望文章能够帮你解决在Swift中的ios – 不可变/可变集合所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)