Created
April 12, 2018 05:26
-
-
Save uruly/8335c8ebe8fd4dd47bb9369f81faee67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Dictionary { | |
| //only [String:Int] | |
| func maxKey() -> [String]?{ | |
| guard let values = Array(self.values) as? [Int] else { return nil } | |
| guard let _ = Array(self.keys) as? [String] else { return nil } | |
| //valueの最大値を取り出す | |
| guard let max = values.max() else { return nil } | |
| var maxKeys:[String] = [] | |
| //辞書の中身をひとつずつ見ていく | |
| for ( key,value ) in self{ | |
| if value as! Int == max{ | |
| print("dic key is \(key) , dic value is \(value)") | |
| maxKeys.append(key as! String) | |
| } | |
| } | |
| return maxKeys | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment