I am using Xcode 10.1 and am an inexperienced programmer in Swift 4.
I can execute the code below (animating a UICollectionView cell when selected) with no warnings or errors:
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let cell = collectionView.cellForItem(at: indexPath) as? CompanyCollectionViewCell else { return }
UIView.animate(withDuration: 0.1, delay: 0, options: [.curveEaseOut], animations: {
cell.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
}) { (finished) in
UIView.animate(withDuration: 0.08, delay: 0, options: [.curveEaseIn], animations: {
cell.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
}, completion: { (finished) in
DispatchQueue.main.async {
self.performSegue(withIdentifier: "showTradeView", sender: self)
}
})
}
}
...but I am concerned about retain cycles within the animation closures.
Do I need to use [unowned self] in the last 'completion:' closure? Do I need to use [unowned cell] in the first animation closure?
and finally (slightly unrelated, sorry) Do I have to call the performSegue code inside DispatchQueue.main, as it seems quite happy to work without this?
Any help is much appreciated.