func someFunc() -> (Int?, Int?, Int?) {
var retVal1:Int? = nil
var retVal2:Int? = nil
var retVal3:Int? = nil
//some other code
//commenting out the line below helped me
//(retVal1, retVal2, retVal3)
return (retVal1, retVal2, retVal3)
}
let myDict: [String: AnyObject] = [ /* bunch of different things */ ]
最好的:
let myDict: [String: SpecificType] = [ /* bunch of similar things */ ]
映射
缺点:
let filteredUserIds = users.filter({ user in user.enabled })
.flatMap { user in user.name != nil ? return user.id : return nil }
好:
let filteredUserIds: [Int] = users.filter({ user in user.enabled })
.flatMap { user in user.name != nil ? return user.id : return nil }
最好的:
let enabledUsers: [User] = users.filter { user in user.enabled }
let filteredUserIds: [Int] = enabledUsers.flatMap {
user in user.name != nil ? return user.id : return nil
}