Delegate Methods in Child Class Sometimes Not Called with Swift 5 Compiler

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



Leave a reply



Submit