Delegate methods in child class sometimes not called with Swift 5 compiler
EDIT: As sunshinejr pointed out here, this has been fixed and will be released together with the next Xcode/Swift version.
I've found the issue, here's how to reproduce it.
class A: UIViewController, UIScrollViewDelegate {
// ...does not implement 'scrollViewDidEndDecelerating'
}
class B: A {
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
// Will not be called!
}
}
What does work:
class A: UIViewController, UIScrollViewDelegate {
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
// Probably empty
}
}
class B: A {
override func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
// Will be called!
}
}
The compiler seems to think that a delegate method is not implemented if the base class did not implement it. If only the child class implements it, it can't find it.
I still can't explain why this behaviour changed with Swift 5, but at least I've found a solution. Maybe someone can give further insights?
Compiler error when assigning the Delegate for a Protocol in Swift iOS
The Known Issues section of the Release Notes says:
You cannot conditionally assign to a property of an optional object.
(16922562)For example, this is not supported:
let window: NSWindow? = NSApplication.sharedApplication.mainWindow
window?.title = "Currently experiencing problems"
So you should do something like if let realObject = object { ... }
Swift 5 breaking my native module export, with error Swift class extensions and categories on Swift classes are not allowed to have +load methods
Had the same issue.
If you will notice , when you run the app on a real device it will work fine.
The problem is in the pods, do pod update.
collectionView didSelectItemAtIndexPath stopped working after migrated to Xcode 10.2
The delegate method was probably renamed. Check that you're implementing:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
Also double-check that you're still setting the controller as a delegate for the UICollectionView.
Related Topics
Use of Undeclared Type 'Attributedstring'
Swift 2.0 'Inout' Function Parameters and Computed Properties
Swift Switch Statement Considered All Cases of Int, But Compiler Still Display Error
How to Speed Up Updating Relationship Among Tables, After One or Both Tables Are Already Saved
How to Demonstrate a Zombie Object in Swift
How to Read a Property List from Data in Swift 3
Suppressing Implicit Returns in Swift
How to Implement Protocol Methods That Return Covariant Selfs
Swiftui Label Text and Image Vertically Misaligned
Swift: Programmatically Enumerate Outgoing Segues from a Uiviewcontroller
How to Animate Bordercolor Change in Swift
Nsurlerrordomain with Code=-1100
How to Set Font Size of Sklabelnode to Fit in Fixed Size (Swift)
How to Disable User Interaction on Swiftui View
What Would Be a Proper Storyboard Example of Combining Nav Bars and Tab Bars in One App