Phillips HUE SDK in Swift

493 views Asked by At


I am very new to Swift! I do have some experience with Objective-C (although it has been around two years since i've really written anything in it). I am trying to use the Phillips HUE SDK with Swift, and am having some trouble! I am trying to re-write the following Objective-C code into Swift:

// Start search for bridges
[self.bridgeSearch startSearchWithCompletionHandler:^(NSDictionary *bridgesFound) {
   //Search complete
   [self showBridgesFound:bridgesFound];
}

I have had no luck looking online for a solution on this, and there is no documentation through Phillips. Has anyone had experience with this, could you please provide assistance?

2

There are 2 answers

2
picciano On BEST ANSWER

The tricky piece is figuring out the syntax of the Swift equivalent of the NSDictionary.

self.bridgeSearch.startSearchWithCompletionHandler { (bridgesFound: [NSObject : AnyObject]!) -> Void in
    self.showBridgesFound(bridgesFound)
}
0
kernelpanic On
self.bridgeSearch!.startSearch { (bridgesFound: [AnyHashable : Any]!) -> Void in
            //self.showBridgesFound(bridgesFound)
            print(bridgesFound)
        }

I think you need to use [AnyHashable : Any] in swift 3 as per this answer.