Revolucent icon

Swift Dictionary

Revolucent | PRO | 04/03/17 10:26:24 PM UTC | 0 ⭐ | 1263 👁️ | Never ⏰ | []
Swift |

470 B

|

None

|

0 👍

/

0 👎

//: Playground - noun: a place where people can play
 
import Cocoa
 
extension Array {
    func dictionary<K: Hashable, V>() -> [K: V] where Element == Dictionary<K, V>.Element {
        var dictionary = [K: V]()
        for element in self {
            dictionary[element.key] = element.value
        }
        return dictionary
    }
}
 
var dictionary = ["x": 7, "y": 3, "n": 14, "z": 9]
dictionary = dictionary.filter{ $0.value % 7 == 0 }.dictionary()
dictionary

Comments