I had a similar issue and I tried @jayjunck's answer but Xcode thrown Method does not override any method from its superclass
. I fixed it by replacing public
with open
to access and override motionBegan
function
In Swift 3,
An open
class is accessible and subclassable outside of the defining module. An open class member is accessible and overridable outside of the defining module.
A public
class is accessible but not subclassable outside of the defining module. A public class member is accessible but not overridable outside of the defining module.
enter code here
extension UIWindow {
override open func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
super.motionBegan(motion, with: event)
guard motion == UIEventSubtype.motionShake else {
return
}
// Shake is detected
}
}
Swift 5
extension UIWindow {
open override func motionBegan(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
super.motionBegan(motion, with: event)
guard motion == UIEvent.EventSubtype.motionShake else {
return
}
// Shake is detected
}
}