UUIDString unexpectedly found nil

600 views Asked by At

I am working on a piece of code using CoreLocation and CLBeaconRegion, but I'm receiving an error:

fatal error: unexpectedly found nil while unwrapping an Optional value

I want to create a region variable holding a CLBeaconRegion like so:

let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "AM_2015-06-10")!, identifier: "AnyMorning")

A bit later in my code, I am calling:

locationManager.startRangingBeaconsInRegion(region)

And when I launch the app, I receive the above error. What is the right way to solve this?

2

There are 2 answers

3
Duyen-Hoa On

"AM_2015-06-10" is not a valid UUIDString! so NSUUID(UUIDString: "AM_2015-06-10")! will crash your application

UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs (Interface Identifiers), are 128-bit values.

0
Clement Tong On

I experienced the same issue. Yes the above answer is correct. Make sure your UUID is 8 characters - 4 characters - 4 characters - 4 characters - 12 characters

The characters should be 0-9 or a-f