1

I want to call a function in ViewDidLoad method with multiple parameters. But it shows the error

Missing argument 'didFindNewAccessory'in call

Here's my code:

override func viewDidLoad() {
        addaccessory(self)
}

func addaccessory(browser: HMAccessoryBrowser, didFindNewAccessory accessory:HMAccessory){

        print("Found new accessory")
        home?.addAccessory(accessory, completionHandler: {
            error in
            if error != nil {

                print("Failed to add it to home")

            }else{
                print("Successfully Added")
                self.home?.assignAccessory(accessory, toRoom: self.room!, completionHandler: {
                    error in

                    if error != nil{
                        print("Unable to add to room")
                    }else{
                        print("Successfuly added to ropom")
                        self.findOrCreatedServioceGroup()
                    }
                })
            }
        })
    }
Irshu
  • 8,248
  • 8
  • 53
  • 65
Swift Developer
  • 247
  • 2
  • 18
  • the function takes two arguments, you are calling it with only one `addaccessory(self)`, as the error message states – rll May 07 '16 at 15:11

1 Answers1

2

You must provide the argument to your function addaccessory. In your case you must have a browser: HMAccessoryBrowser and accessory:HMAccessory, that's why your call addaccessory(self) is wrong with invalid argument. You should have something like this :

addaccessory(yourBrowser, didFindNewAccessory: yourAccessory)
Chajmz
  • 729
  • 5
  • 11