diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index 7eb76c4e4e17c3..021ada1852cf9c 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -364,13 +364,10 @@ - (void)suspend @synchronized(self) { _suspended = YES; - NSMutableArray * devicesToSuspend = [NSMutableArray array]; + NSArray * devicesToSuspend; { std::lock_guard lock(*self.deviceMapLock); - NSEnumerator * devices = [self.nodeIDToDeviceMap objectEnumerator]; - for (MTRDevice * device in devices) { - [devicesToSuspend addObject:device]; - } + devicesToSuspend = [self.nodeIDToDeviceMap objectEnumerator].allObjects; } for (MTRDevice * device in devicesToSuspend) { @@ -392,13 +389,10 @@ - (void)resume @synchronized(self) { _suspended = NO; - NSMutableArray * devicesToResume = [NSMutableArray array]; + NSArray * devicesToResume; { std::lock_guard lock(*self.deviceMapLock); - NSEnumerator * devices = [self.nodeIDToDeviceMap objectEnumerator]; - for (MTRDevice * device in devices) { - [devicesToResume addObject:device]; - } + devicesToResume = [self.nodeIDToDeviceMap objectEnumerator].allObjects; } for (MTRDevice * device in devicesToResume) { @@ -490,7 +484,7 @@ - (void)cleanupAfterStartup // devices before we start invalidating. MTR_LOG("%s: %@", __PRETTY_FUNCTION__, self); os_unfair_lock_lock(self.deviceMapLock); - NSEnumerator * devices = [_nodeIDToDeviceMap objectEnumerator]; + auto * devices = [self.nodeIDToDeviceMap objectEnumerator].allObjects; [_nodeIDToDeviceMap removeAllObjects]; os_unfair_lock_unlock(self.deviceMapLock); diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm index 4f19035f27da85..1edcb4928943a1 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm @@ -426,7 +426,7 @@ - (void)cleanupAfterStartup // devices before we start invalidating. MTR_LOG("%s: %@", __PRETTY_FUNCTION__, self); os_unfair_lock_lock(self.deviceMapLock); - NSEnumerator * devices = [self.nodeIDToDeviceMap objectEnumerator]; + auto * devices = [self.nodeIDToDeviceMap objectEnumerator].allObjects; [self.nodeIDToDeviceMap removeAllObjects]; os_unfair_lock_unlock(self.deviceMapLock);