Collection was mutated while being enumerated error in objective C
Because your logic is flawed. It is not permited to mutate a collection during enumeration. And in the latter case, NSMutableArray doesn't know you're trying to emumerate it, only in the first case. And then it complains, since this is a semantic error. You should generally solve these kinds of problems by mutable copying the array and mutating the copy, then replacing the original one by the updated copy.
Error when attempting to remove node from parent using fast enumeration
Behavior may change between iOS versions. It may have actually crashed at some point or very rarely even in Xcode 5, you just didn't get to see it.
The problem is easily circumvented by delaying the execution of the removeFromParent method. This should do the trick because actions are evaluated at a specific point in the game loop rather than instantaneously:
[self enumerateChildNodesWithName:@"name" usingBlock:^(SKNode *node, BOOL *stop) {
if (node.position.y < 0 || node.position.x>320 || node.position.x<0) {
[node runAction:[SKAction removeFromParent]];
}
}];
If this won't work use the "old trick": filling an NSMutableArray with to-be-deleted items and removing the nodes in that array after enumeration:
NSMutableArray* toBeDeleted = [NSMutableArray array];
[self enumerateChildNodesWithName:@"name" usingBlock:^(SKNode *node, BOOL *stop) {
if (node.position.y < 0 || node.position.x>320 || node.position.x<0) {
[toBeDeleted addObject:node];
}
}];
for (CCNode* node in toBeDeleted)
{
[node removeFromParent];
}
CoreData change relationships in a loop
The problem is that you can't change (mutate) a collection like your greenCategory.items
set while you're looping over it, which is what you're doing when you change the category of the items in that set. What you have to do is create a separate collection and loop over it instead.
NSArray *greenCategoryItemsArray = [greenCategory.items allObjects];
for (Item *aItem in greenCategoryItemsArray) {
[aItem setCategory:blueCategory];
}
Related Topics
Could Not Cast Value of Type 'Uitableviewcell' to '(Appname).(Customcellname)'
Asset Catalog: Access Images with Same Name in Different Folders
iOS 11 Layout Guidance About Safe Area for iPhone X
Application(...Continue Useractivity...) Method Not Called in iOS 13
Failed to Load Optimized Model - Googlemaps Sdk iOS
Passing Data Back from a Modal View in Watchkit
How to Save Created PDF in Document Folder and Merge in iOS
Tap Gesture on Animating Uiview Not Working
How to Send Data from iPhone to Apple Watch in Os2 in Objective-C
How to Effectively Process Uitouches in a Multitouch Sequence
Does Webkit in iOS 11 (Beta) Support Webrtc
Change the Root View of Uihostingcontroller in Swiftui
Uitextview Adding New Line Unintentionally