enum FriendType{
case normal, best
}
class Friend{
var name: String
var type: Friendtype
}
var FriendList = [
Friend(name: "a", type: .normal)
Friend(name: "b", type: .normal)
Friend(name: "c", type: .best)
Friend(name: "d", type: .normal)
]
let groupedFriends : [FriendType : [Friend]] = Dictionary(grouping: FriendList, by: {$0.type})
//let groupedFriends = Dictionary(grouping: FriendList, by:{(friend) -> FriendType in return friend.type} )
//[normal: [{name:"a",normal}, {name:"b",normal}, {name:"d", normal}]], [best: [{name: "c", best}]]
groupedFriends[.normal] //[{name:"a",normal}, {name:"b",normal}, {name:"d", normal}]
groupedFriends[.best] //[{name: "c", best}]