2017-08-16 7 views
1

の最後に空の名前を持つ移動オブジェクトは、私は次のように私は、ソートてるの配列を持っている:リゾートスウィフト配列 - 配列

contactsArray = unified.sorted{$0.name.localizedCaseInsensitiveCompare($1.name) == ComparisonResult.orderedAscending} 

問題は、私が移動する空の文字列の元""を持つオブジェクトたいです配列の終わりに移動します。ここで最も効率的なソリューションを探してください。

答えて

1

これを試してみてください:

contactsArray = unified.sorted { (a, b) -> Bool in 
    if a.name.isEmpty { 
     return false 
    } else if b.name.isEmpty { 
     return true 
    } else { 
     return a.name.localizedCaseInsensitiveCompare(b.name) == .orderedAscending 
    } 
}