Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. //
  2. // DictionaryExtensions.swift
  3. //
  4. //
  5. // Created by Tommie N. Carter, Jr., MBA on 12/14/15.
  6. // Copyright © 2015 MING Technology. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10.  
  11.  
  12.  
  13. extension Dictionary where Value : Equatable {
  14. // func allKeysForValue<K, V : Equatable>(dict: [K : V], val: V) -> [K] {
  15. // return dict.filter{ $0.1 == val }.map{ $0.0 }
  16. // }
  17. func allKeysForValue(val : Value) -> [Key] {
  18. return self.filter { $1 == val }.map { $0.0 }
  19. }
  20. func someKeyFor(value: Value) -> Key? {
  21.  
  22. guard let index = indexOf({ $0.1 == value }) else {
  23. return nil
  24. }
  25.  
  26. return self[index].0
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement