Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not cast value of type 'NSTaggedPointerString' (0x10146ecd8) to 'NSNumber' (0x102675600)

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.

like image 870
Nyein Ei Ei Tun Avatar asked Nov 21 '25 09:11

Nyein Ei Ei Tun


1 Answers

id = Int((content[0]["id"] as! NSString).floatValue)

This works fine for me. Content is json array

like image 85
XenoX Avatar answered Nov 23 '25 02:11

XenoX