-1

So I'm trying to do some programming with Phillips HUE lights and I've already made a bridging header and imported the necessary info to use the Hue SDK with Swift, but all of the guidance is written for Objective-C. I'm having trouble understanding/declaring this function in Swift:

// Start search for bridges
[self.bridgeSearch startSearchWithCompletionHandler:^(NSDictionary *bridgesFound) {

    // Search is complete, handle results (dictionary contains IP and mac addresses of bridges found)

    [self showBridgesFound:bridgesFound];
}

When I go to call this in Swift, I type bridgeSearch.startSearch() and Xcode automatically adds this with a Completion handler

//Search for bridges
let bridgeSearch: PHBridgeSearching = PHBridgeSearching()        
bridgeSearch.startSearch { ([AnyHashable : Any]?) in
        //code
}

I know how to get the information (found IP addresses) stored into an NSDictionary in Obj-C, but I'm not sure what to do here in terms of storing the IP addresses into some sort of data structure.

Thanks!

matt
  • 515,959
  • 87
  • 875
  • 1,141
Nick Mullen
  • 107
  • 2
  • 10

1 Answers1

2

The problem is merely that you have not given the incoming parameter any name. Give it one:

bridgeSearch.startSearch { bridgesFound in
    // code involving bridgesFound
}
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • That was easy, whoops, thanks. So will bridgesFound then be automatically filled with values like the NSDictionary? – Nick Mullen Nov 26 '17 at 01:07
  • Yes, it's a Swift Dictionary. The Swift code is an exact Swift translation of your original Objective-C code. – matt Nov 26 '17 at 01:07