2014-10-28 37 views
0

我有一個數組從字典被提取與.allKeys,我希望使用sorted()函數這樣排序與AnyObjects陣列在夫特

func order(s1: Int, s2: Int) -> Bool { 
     return s1 < s2 
    } 
let array = sorted(dictionary.allKeys, order) 

然而,排序,類型.allKeys產率被AnyObject和由於我在order()函數中使用了Int,所以出現錯誤。有任何想法嗎?

+0

你是如何聲明'dictionary'? – 2014-10-28 08:30:05

回答

2
let arraySorted = dictionary.allKeys.sorted() { ($0 as Int) < ($1 as Int) } 

更加簡潔,並應做工精細

+0

感謝您的幫助! – Natanel 2014-10-28 09:18:17

0

試試這個:

let array = sorted(dictionary.allKeys as Array<Int>, order) 
+0

感謝您的幫助! – Natanel 2014-10-28 09:17:07