I am trying to make a loop in my code like this:
for row in rows! {
print("Row",row)
let pin = Pin.init(latitude: row[0] as! Float, longitude: row[1] as! Float, pinType: row[2] as! String, beaconID: row[3] as! Int, altitude: row[4] as! Float)
pinList.append(pin)
}
Here, row is an Any and I'm creating the pin object based on the row's values.
Here is my Pin Class:
class Pin {
var latitude:Float
var longitude:Float
var pinType:String
var beaconID:Int
var altitude:Float
init(latitude:Float, longitude:Float, pinType:String, beaconID:Int, altitude:Float){
self.latitude = latitude
self.longitude = longitude
self.pinType = pinType
self.beaconID = beaconID
self.altitude = altitude
}
}
But I got this error:
Could not cast value of type '
NSTaggedPointerString' (0x10146ecd8) to 'NSNumber' (0x102675600).
while I am trying to create the Pin object.
Can anyone help me to fix this problem? Thanks.
id = Int((content[0]["id"] as! NSString).floatValue)
This works fine for me. Content is json array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With