I am trying to write an extension to a UIKit class, but am running into a
can’t-win situation:
The code I ‘want’ to write looks like:
public extension UISplitViewController {
override public func viewDidLoad() {
super.viewDidLoad()
if UIDevice.current.userInterfaceIdiom == .pad {
preferredDisplayMode = .automatic
} else {
preferredDisplayMode = .primaryOverlay
}
}
}
This generates the error message
/Users/rlaurb/Projects/Cooks-Memory/Cooks-Memory/AppDelegate.swift:131:23:
Overriding instance method must be as accessible as the declaration it overrides
/Users/rlaurb/Projects/Cooks-Memory/Cooks-Memory/AppDelegate.swift:131:23:
Overridden declaration is here (UIKit.UIViewController)
But I can’t change the access control of the function to ‘open’, because I get
the warning that the function can’t be “more” accessible than the extension.
And I can’t change the extension’s access to ‘open’ because apparently
extensions can’t be open.
Now I don’t want to get into a debate about whether this code works — it’s just
an experiment — but is it even possible to express this idea?? I.e., is it
possible to express this idea without subclassing?
Cheers,
Rick Aurbach
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users