33 lines
1000 B
Swift
33 lines
1000 B
Swift
//
|
|
// DictionaryExtensions.swift
|
|
// EZSwiftExtensions
|
|
//
|
|
// Created by Goktug Yilmaz on 15/07/15.
|
|
// Copyright (c) 2015 Goktug Yilmaz. All rights reserved.
|
|
//
|
|
import UIKit
|
|
|
|
extension Dictionary {
|
|
/// EZSE: Returns a random element inside Dictionary
|
|
public func random() -> NSObject {
|
|
let index: Int = Int(arc4random_uniform(UInt32(self.count)))
|
|
return Array(self.values)[index] as! NSObject
|
|
}
|
|
|
|
/// EZSE: Combines the first dictionary with the second and returns single dictionary
|
|
public func union(other: Dictionary) -> Dictionary {
|
|
var temp = self
|
|
for (key,value) in other {
|
|
temp.updateValue(value, forKey:key)
|
|
}
|
|
return temp
|
|
}
|
|
}
|
|
|
|
/// EZSE: Combines the first dictionary with the second and returns single dictionary
|
|
public func += <KeyType, ValueType> (inout left: Dictionary<KeyType, ValueType>, right: Dictionary<KeyType, ValueType>) {
|
|
for (k, v) in right {
|
|
left.updateValue(v, forKey: k)
|
|
}
|
|
}
|