HomeKit completion block in Swift: Cannot convert the expression’s type ‘Void’ to type ‘String!’

The parameters for your completionHandler closure are reversed, they should be:

(home: HMHome!, error: NSError!)

Also note that you don’t need to specify the types for the parameters, since the method signature specified them for you – thus you can simply list the parameter names you want to use, and they will automatically be assured to be of the correct type, for example:

homeManager.addHomeWithName("My House", completionHandler:{
    home, error in
    if error { NSLog("%@", error) }
    })

edit

Also note that when I wrote ‘you can simply list the parameter names you want to use, and they will automatically be assured to be of the correct type’, that is to say that they will be typed according to the order in which they are listed – e.g. if you had used error, home in instead, then those would be your parameter names however the parameter error would be of type HMHome!, and home would be of type NSError! (since that is the order in which they appear in the parameter list for the closure in the method’s signature)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)