var blockOperations = [NSBlockOperation]()
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
if type == .Insert {
blockOperations.append(NSBlockOperation(block: {
self.collectionView?.insertItemsAtIndexPaths([newIndexPath!])
}))
}
}
func controllerDidChangeContent(controller: NSFetchedResultsController) {
collectionView?.performBatchUpdates({
for operation in self.blockOperations {
operation.start()
}
}, completion: { (completed) in
print("completed")
})
}
This is my code for inserting messages into my collection view.
I need block operations so that when a message is delayed it can be inserted in a block matter.
The problem is every time I dismiss the viewController
the print("completed")
duplicates. which means that i have a memory leak.
And deinit
never gets called unless I remove block operations, how can I release the block operation when I leave the viewController
?