Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Int? to CLBeaconMajorValue

Tags:

ios

swift

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

like image 877
Daij-Djan Avatar asked Jun 02 '14 23:06

Daij-Djan


1 Answers

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!)
like image 108
Leandros Avatar answered Oct 19 '22 13:10

Leandros