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")
})
}
这是我将消息插入我的集合视图的代码。
我需要块操作,以便在消息被延迟时可以插入块事件中。
问题是我每次都忽略了viewController
print("completed")
重复项。这意味着我有内存泄漏。
除非我删除块操作,否则永远不会调用deinit
,当我离开viewController
时如何释放阻止操作?