1) I cannot understand why is self
not required in first closure. Usually you get a compile-time error that goes something like this: "add self to make capture semantics explicit". myCollectionView
is an IBOutlet and myItems
is a property, they are both strongly reference by self
.
2) Is it correct to write [unowned self]
in second closure? Am I right to assume that because myCollectionView
is referenced strongly by self
, using self
in its method's completion closure would create a retain cycle is I don't write [weak self]
/[unowned self]
? The second closure DOES require referencing self
explicitly unlike the first one.
guard let index = myItems.index(of: someItem) else { return }
myCollectionView.performBatchUpdates({
myCollectionView.deleteItems(at: [IndexPath(item: index, section: 0)])
myItems.remove(at: index)
}, completion: {[unowned self] _ in
self.doSomething()
})