| | 267 | + (void)setObjectForPendingDelete:(NSManagedObject *)objectToDelete |
| | 268 | { |
| | 269 | [pendingDeleteObjects addObject:objectToDelete]; |
| | 270 | } |
| | 271 | |
| | 272 | /*! |
| | 273 | * @brief Deletes pending objects |
| | 274 | * |
| | 275 | * Deletes all objects in the pending queue, but calls shouldDelete first to make sure it should |
| | 276 | * be deleted. This is also used as a hack to work around CD apparent inability to make KVO |
| | 277 | * notifications during an object delete when it is within an KVO notification. |
| | 278 | */ |
| | 279 | + (void)deletePendingObjects |
| | 280 | { |
| | 281 | NSManagedObjectContext *mainMoc = [SapphireMetaDataSupport sharedInstance]->mainMoc; |
| | 282 | [mainMoc processPendingChanges]; |
| | 283 | while([pendingDeleteObjects count]) |
| | 284 | { |
| | 285 | NSManagedObject *obj; |
| | 286 | NSSet *pendingObjects = [pendingDeleteObjects copy]; |
| | 287 | [pendingDeleteObjects removeAllObjects]; |
| | 288 | NSEnumerator *objEnum = [pendingObjects objectEnumerator]; |
| | 289 | while((obj = [objEnum nextObject]) != nil) |
| | 290 | { |
| | 291 | if([obj isDeleted]) |
| | 292 | continue; |
| | 293 | if([obj managedObjectContext] != mainMoc) |
| | 294 | continue; |
| | 295 | if(![obj respondsToSelector:@selector(shouldDelete)] || [obj shouldDelete]) |
| | 296 | [mainMoc deleteObject:obj]; |
| | 297 | } |
| | 298 | [pendingObjects release]; |
| | 299 | [mainMoc processPendingChanges]; |
| | 300 | } |
| | 301 | } |
| | 302 | |