Swift中字典有个删除方法叫removeAtIndex的方法,参数居然是个index
/// Remove the key-value pair at index `i`
///
/// Invalidates all indices with respect to `self`.
///
/// Complexity: O(\ `count`\ ).
mutating func removeAtIndex(index: DictionaryIndex)
首先说一点,字典是无序的,怎么才能找到这个index?
command点进去,再点进去,然后- -你就迷茫了
最后找到的还是叫这个
DictionaryIndex
所以说- -,还是需要一个叫DictionaryIndex类型的变量来做。感谢老左,机智的发现了这个方法
/// Returns the `Index` for the given key, or `nil` if the key is not
/// present in the dictionary.
func indexForKey(key: Key) -> DictionaryIndex?
subscript (position: DictionaryIndex) -> (Key, Value) { get }
subscript (key: Key) -> Value?
例:
dic.removeAtIndex(dic.indexForKey("age")!)