我想在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()
}
})
}
})
}
答案 0 :(得分:1)
您必须为函数addaccessory
提供参数。
在您的情况下,您必须拥有browser: HMAccessoryBrowser
和accessory:HMAccessory
,这就是您的无效参数调用addaccessory(self)
错误的原因。
你应该有这样的东西:
addaccessory(yourBrowser, didFindNewAccessory: yourAccessory)