1

我想用多个参数在 ViewDidLoad 方法中调用一个函数。但它显示了错误

调用中缺少参数“didFindNewAccessory”

这是我的代码:

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

1 回答 1

2

您必须为您的函数提供参数addaccessory。在您的情况下,您必须有一个browser: HMAccessoryBrowserand accessory:HMAccessory,这就是为什么您的电话addaccessory(self)因无效参数而出错的原因。你应该有这样的东西:

addaccessory(yourBrowser, didFindNewAccessory: yourAccessory)
于 2016-05-07T11:09:23.950 回答