问题
I use this line of code in an app with XCode 10 in order to dim the home indicator on iPhone X and associated edgeless apple devices.
override func prefersHomeIndicatorAutoHidden() -> Bool {
return true
}
Now the funny thing is, I have an exact copy of this app and on one copy the code works, whilst on the over the code does not compile:
Method does not override any method from its superclass
Indeed when I start typing "prefers..." , prefersHomeIndicatorAutoHidden appears as a read-only property on the one hand, whilst it does appear as a method on the other hand, and gets the override prefix by default.
Thanks for taking the time,
Best
EDIT WITH SOLUTIONS thanks to @inokey
Solution 1: check deployment (starting i0S 12,
prefersHomeIndicatorAutoHidden
cannot be overridden as a method)Solution 2 :
override var prefersHomeIndicatorAutoHidden : Bool { return true }
回答1:
I assume that default deploy target in Xcode 10 is 12 and your previous project is 11 or 10, so it just reflects the changes in API.
Changes in SDK indicate that this was changed
回答2:
in Xcode 10 = Swift 4.2 (Sep 2018)
Just use the code below:
override var prefersHomeIndicatorAutoHidden: Bool { return true }
来源:https://stackoverflow.com/questions/52387158/cannot-override-prefershomeindicatorautohidden-method