Phillips HUE SDK in Swift

醉酒当歌 提交于 2019-12-11 03:15:25

问题



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?


回答1:


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)
}



回答2:


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.



来源:https://stackoverflow.com/questions/27573922/phillips-hue-sdk-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!