---
title: "addAndSetupAccessories(with:completionHandler:)"
framework: homekit
role: symbol
role_heading: Instance Method
path: "homekit/hmhome/addandsetupaccessories(with:completionhandler:)"
---

# addAndSetupAccessories(with:completionHandler:)

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

## Declaration

```swift
func addAndSetupAccessories(with payload: HMAccessorySetupPayload, completionHandler completion: @escaping @Sendable ([HMAccessory]?, (any Error)?) -> Void)
```

```swift
func addAndSetUpAccessories(payload: HMAccessorySetupPayload) async throws -> [HMAccessory]
```

## Discussion

Discussion Use this method to add accessories that have already been deployed (for example, accessories that have HomeKit support added as a firmware update), or accessories for which scanning a QR code would be difficult. Your app provides the accessory’s HomeKit code using a setup payload. For details on the payload’s content, please join the MFi Program. During this process, the user assigns the accessory to a room and configures its services.

## Topics

### Defining the Setup Payload

- [HMAccessorySetupPayload](homekit/hmaccessorysetuppayload.md)

## See Also

### Managing accessories

- [accessories](homekit/hmhome/accessories.md)
- [addAndSetupAccessories(completionHandler:)](homekit/hmhome/addandsetupaccessories(completionhandler:).md)
- [addAccessory(_:completionHandler:)](homekit/hmhome/addaccessory(_:completionhandler:).md)
- [assignAccessory(_:to:completionHandler:)](homekit/hmhome/assignaccessory(_:to:completionhandler:).md)
- [removeAccessory(_:completionHandler:)](homekit/hmhome/removeaccessory(_:completionhandler:).md)
- [supportsAddingNetworkRouter](homekit/hmhome/supportsaddingnetworkrouter.md)
- [unblockAccessory(_:completionHandler:)](homekit/hmhome/unblockaccessory(_:completionhandler:).md)
- [HMAccessory](homekit/hmaccessory.md)
