Int? to CLBeaconMajorValue
ios, swift
Solution
You have to cast the value.
Since `CLBeaconMajorValue` is a `UInt16` `typealias`, you can do it like this:
let m = UInt16(major!)
You can even do this:
let m = CLBeaconMajorValue(major!)
Problem
I started with apple swift today (as many others ;)) and I struggle with reading a plist. I read a plist entry from my info.plist which is an NSArray where each entry is a Dictionary. ``` let regionsToMonitor = NSBundle.mainBundle().infoDictionary["Regions"] as Array<Dictionary<String,AnyObject>> for regionToMonitor in regionsToMonitor { ... ``` one key for each region is a major. in objC terms a NSNumber. I read it as: ``` let major: Int? = regionToMonitor["major"] ? regionToMonitor["major"]!.integerValue : nil; ``` now I need it as a CLBeaconMajorValue so I try to cast it to that with `as` ``` clRegion = CLBeaconRegion(proximityUUID: uuid, major: major! as CLBeaconMajorValue, identifier: identifier) ``` doesn't work. the UUID and identifier do work (Ive checked with another constructor, but the not the init this is also not good ``` let m = major! as CLBeaconMajorValue ``` how do I convert my NSNumber / int? to the CLBeaconMajorValue