Super methods should be able to be marked as required and it should be an error to not call them

I just lost around 8 hours to a typo that, IMO, Swift shouldn't even allow to happen. It is easy to see in isolation here, but it took forever to find in real life:

override func viewDidAppear(_ animated: Bool) {
	super.viewDidDisappear(animated)
	// lots of other distracting stuff..
}

UIViewController subclasses have to call the appropriate super implementation when overriding these appearance methods and when you don't, things often work fine in most - but not all - circumstances and so this sort of bug goes hidden and unnoticed for a long time. When you finally notice weird behavior later, it's sometimes long after you wrote the actual bug and you go down unrelated rabbit holes. For hours. Over the course of two days. (ARGH!)

Objective-C has NS_REQUIRES_SUPER and I cannot understand why this doesn't seem to exist or be enforced in Swift.

5 Likes

:-( Just a task that's never risen to the top of the priority list. It's filed as SR-6417. A tricky bit is that doing it right requires coming up with a name for the feature in Swift, as well as deciding how to indicate that you don't want to call super in rare circumstances.

3 Likes

Meanwhile you can use swiftlint to catch these errors SwiftLint/Rules.md at main · realm/SwiftLint · GitHub

1 Like

This sounds like it might be a pretty straightforward evolution proposal for someone who's good at that sort of thing?

Yep, it's tagged StarterProposal (if not quite StarterBug) for that reason.

It always look like straightforward until you dig in the subject. There already has been very long discussion about that feature and it is very hard to cover everyone needs.

1 Like

I remember seeing some of those discussions. The fact that they were long and didn't please every single person doesn't change the fact that it is sorely needed and would save countless developer hours.