Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // DictionaryExtensions.swift
- //
- //
- // Created by Tommie N. Carter, Jr., MBA on 12/14/15.
- // Copyright © 2015 MING Technology. All rights reserved.
- //
- import Foundation
- extension Dictionary where Value : Equatable {
- // func allKeysForValue<K, V : Equatable>(dict: [K : V], val: V) -> [K] {
- // return dict.filter{ $0.1 == val }.map{ $0.0 }
- // }
- func allKeysForValue(val : Value) -> [Key] {
- return self.filter { $1 == val }.map { $0.0 }
- }
- func someKeyFor(value: Value) -> Key? {
- guard let index = indexOf({ $0.1 == value }) else {
- return nil
- }
- return self[index].0
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement