Make your class a delegate of HMHomeManager:
import UIKit import HomeKit class HomeManagerViewController: UITableViewController, HMHomeManagerDelegate { var homeViewController: HomeViewController? = nil var myHomeManager:HMHomeManager? = nil var homes = [AnyObject]() // datasource for tableview
Your HMHomeManager must be initialized first (you mentioned that you already did this), and your class must be its delegate.
override func viewDidLoad() { super.viewDidLoad() myHomeManager = HMHomeManager() myHomeManager!.delegate = self
You add Home to any function you need (for example, when the user presses the + button to insert a new house into the list of tables)
HMHomeManager must have time to connect to the homekit database
func insertNewObject(sender: AnyObject) { myHomeManager!.addHomeWithName( uniqueHomeName , completionHandler: { (home: HMHome!, error: NSError!) -> Void in if (error != nil) { // adding the home failed; check error for why NSLog("Error : %@",[error.localizedDescription]) } else { // success! // Insert home at bottom of datasource array and bottom of tableview cells self.homes.append(home) let indexPath = NSIndexPath(forRow: self.homes.count-1, inSection: 0) self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) } }) }
Then you update your tableviews data source in the delegate method homeManagerDidUpdateHomes.
This function is called when the HMHomeManager has completed initialization and will provide you with an array of any previously added houses.
//
At the first launch of the application, a request for access to its " Accessory data " should appear.
Make sure you click โOKโ for this.

Also: add "HomeKit" according to your application rights:
- Select your application Purpose .
- Select the Features tab.
- Switch " HomeKit " to "On".
- Enter developer ID, etc.
attached image example

source share