Search code examples
iosswiftibeacon

ibeacon app development using swift


everyone, I am a new one to iOS app development using swift. I am studying a ibeacon app sample code which downloaded from the https://github.com/SelimSalihovic/CityOS-iBeacon-Swift-Tutorial. while I was running the code, there are errors in the code as shown the following page, could you help me how to solve it, please! Thanks in advance!

first error

second erro


Solution

  • The first one is easily solveable by unwrapping the value (the exclamation mark)

    NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D")!
    

    Second and third error are due to the beacons array not declaring the content's type (AnyObject means it can't be any class, which is not guaranteed to have the properties the code is looking for) so just go to line 16 and make the following change

    var beacons : [CLBeacon] = []
    

    However this will still not compile because the LocationServices framework hasn't been imported in the project, to do so just add

    import CoreLocation
    

    There will be some more errors now, specifically at line 26 and 55 in BeaconTableViewController

    Fix-It has the right suggestion for these, basically you need to cast note.object by adding as! [CLBeacon] and remove the unwrapping on switch proximity because the value isn't optional

    The code now compiles properly for me, I'm not sure it will work because I can't test right now, but it should be a step in the right direction

    Good luck with your journey in iBeacons, they're a pretty fun technology to work with