2015-09-15 76 views

回答

0

Swift中一个非常不寻常但有效的语法是将值设置为nil并带有下标。

fruits["apple"] = nil 
0
var myDict = ["foo":"bar"] 
    myDict.removeValueForKey("foo") 

我是否错过了您的问题?

0

搬进一座字典使用重点,你既可以使用removeValueForKeyremoveAtIndex

例子,让我们说我们有一个字典称为

var my = [String:String]() 
my = ["name":"James","age":"75","location":"StackOverflow"] 

而且我要删除的价值为位置< ----关键

第一种方法:

my.removeValueForKey("location") 

方法二:

my.removeAtIndex(my.indexForKey("location")!) 

希望帮助你,请你张贴了,当你问一个问题试图代码。 :)