Instance Method

addAccessory(_:completionHandler:)

Adds a new accessory to the home.

Declaration

func addAccessory(_ accessory: HMAccessory, completionHandler completion: @escaping (Error?) -> Void)

Parameters

accessory

The accessory to add to the home.

completion

The block executed after the request is processed.

error

nil on success; otherwise, error object indicating the reason for failure.

Discussion

You discover accessories to add to a home using the HMAccessoryBrowser class. Newly added accessories are automatically added to the room returned by roomForEntireHome().

See Also

Managing Accessories

var accessories: [HMAccessory]

The collection of accessories that are part of the home.

func addAndSetupAccessories(completionHandler: (Error?) -> Void)

Finds and adds nearby accessories to the home.

func addAndSetupAccessories(with: HMAccessorySetupPayload, completionHandler: ([HMAccessory]?, Error?) -> Void)

Finds and adds nearby accessories to the home using a HomeKit code provided by your app.

class HMAccessory

A home automation accessory, like a garage door opener or a thermostat.