我想在枚举时从 NSMutableDictionary 中删除一个键,但如果我这样做,应用程序将崩溃,因为我在枚举它时对其进行了变异。这是代码:
for(id key in BluetoothDeviceDictionary) {
UIButton* btn = [BluetoothDeviceDictionary objectForKey:key];
MCPeerID* DevicePeer = [MCPeerID alloc];
DevicePeer = key;
if (DevicePeer.displayName == peerID.displayName) {
[btn removeFromSuperview];NSLog(@"LostPeer!!!!DEL");
CountNumberOfBluetoothDevices = CountNumberOfBluetoothDevices - 1;
[BluetoothDeviceDictionary removeObjectForKey:key2];
}
}
我该怎么做?