views:

209

answers:

2

I want to iterate through all of the objects in my NSManagedObjectContext, and update them manually. Then, every managed object should be updated. What's the best way to do this?

+1  A: 
Tim
Casting is not necessary, all of the fetch methods and the -objectAtIndex: method return id. All of the properties in a NSManagedObject can be accessed via KVC and can be queried via -doesRespondToSelector:
Marcus S. Zarra
True, but I tend to get frustrated with code that's littered with `doesRespondToSelector:` calls - casting, while not strictly necessary, can be a lot more readable down the road.
Tim
+2  A: 

This seems like a very heavy handed approach to the problem. If the data is getting loaded with bad data then i would strongly suggest fixing it while you are importing the data. Tim's answer will work for what you are doing but I strongly suspect you are coming at this wrong. Iterrating through the whole database looking for potentially bad data is very inefficient.

Marcus S. Zarra
I would agree with this approach much more than the answer I posted - if you know wrong data is being imported "at the first time," then you should be able to correct that on import, not later.
Tim