I am attempting to use a hash that contains a nullable int as a value. The below is the code.
var facs:[(pk:Int,phone:Int?,name:String)] = []
var phone: AnyObject? = fac["phone"]!
var phoneLong:Int?;
if(phone == nil){
phoneLong = nil
}
else{
phoneLong = phone as? Int
}
var id = fac["id"]! as Int
var name = fac["name"]! as String
facs.append(pk:id, phone:phoneLong, name:name)
However, I get a compile error on the facs.append
line that states Type 'T' does not conform to protocol 'IntegerLiteralConvertible'
. I've tried a few variations, and the only way I can get rid of the error is to make phone a non-nullable int, which is not what I need. Thoughts?
It looks like the append
method doesn't correctly detect the parameters as a tuple - just make that explicit by assigning the tuple to a variable:
let params = (pk:id, phone:phoneLong, name:name)
facs.append(params)