aloparz aloparz - 4 months ago 29
Swift Question

beacon minor variable global

i need ur help! i do an app and i need said that the "minorBeacon" do a global variable, because in other ViewController i will called. but i can't and the other problem is convert this data to "Int"

func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {

if let beacon = beacons.first {
var minorBeacon : Int = beacon.minor
print(minorBeacon)


}


the problem says
"cannot convert value type "NSNumber" to specified type "Int" " help me please!!

Thanks Guys ! :)

Answer

You can user intValue to get the NSNumber's value as a Swift Int:

func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {

if let beacon = beacons.first {
    var minorBeacon = beacon.minor.intValue
    print(minorBeacon)
}