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 }
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
in Xcode 10 = Swift 4.2 (Sep 2018)
Just use the code below:
override var prefersHomeIndicatorAutoHidden: Bool { return true }
Related
I am writing a Focus system extension (sandboxed, Cocoa, entitlements set) for macOS 13/Ventura using Xcode 14.2
I have the extension loading it's UI into the macOS system settings > Focus pane.
so here are the issues:
Even though it is loaded, it doesn't seem to ever run the perform() function when the UI is changed by the user or the user invokes Focus > Do Not Disturb.
What can be done in the perform() function? Like, what is supposed to go there? Nothing seems to work.
import AppIntents
struct MacOSFocus: SetFocusFilterIntent {
static var title: LocalizedStringResource {
return "Focus Settings"
}
// The description as it appears in the Settings app
static var description: LocalizedStringResource? = "Focus Settings" // name under Minus icon in options list
// How a configured filter appears on the Focus details screen
var displayRepresentation: DisplayRepresentation {
return DisplayRepresentation(stringLiteral: "Focus Settings") // name under filter once added to Foucs
}
#Parameter(title: "Show Task Bar", default: false)
var showDefaultTaskBar: Bool
#Parameter(title: "Start Timer")
var startTimer: Bool
func perform() async throws -> some IntentResult {
// This doesnt seem to run
// What can I put here?
// I need to write string data to a text file somewhere or communicate with the host app in some way.
return .result()
}
}
Just trying to get unstuck. Thanks for any help.
Tried adding an NSLog() call in the perform() function for debugging. Even tried using NSSound.beep() just to check that it is getting called. Didn't work.
I have updated my MSDKUI project from 2.0.0 to 2.1.1 and have made some changes make the navigation work.
My project is based on "GuideMeToHERE". The updated podfile is:
target 'GuideMeToHERE' do
platform :ios, '12.0'
pod 'HEREMapsUI', '2.1.1'
end
Voice Guidance stops working when I set up the GuidanceManeuverMonitor.
This is my function setUpGuidanceViews(route: NMARoute)
private func setUpGuidanceViews(route: NMARoute) {
NMANavigationManager.sharedInstance().delegate = self
//*** If I comment these three lines out the voice guidance works!
maneuverMonitor = GuidanceManeuverMonitor(route: route)
maneuverMonitor.delegate = self
customizeGuidanceManeuverView()
What can I do to have the maneuver monitor working and have voice guidance?
I fixed it by changing one of the delegates to be more specific:
//NMANavigationManager.sharedInstance().delegate = self
NavigationManagerDelegateDispatcher.shared.add(delegate: self)
Additionally to #CSchwarz answer I had to implement the following NMANavigationManagerDelegate function:
func navigationManager(_ navigationManager: NMANavigationManager, shouldPlayVoiceFeedback text: String?) -> Bool {
return true
}
and
NavigationManagerDelegateDispatcher.shared.add(delegate: self)
As shown above, in the Xcode playground, I am trying to extend the protocol Exercise to have two more computed properties, caloriesBurnedPerMinute and description. When I want to run this part of code in the playground, the "play button" at the extreme bottom left corner appears as grey, indicating that it cannot run the code until line 20. However, if I just want to run the code until line 14, as shown below, the "play button" appears as blue, indicating that it can run the code until line 14.
May I know if there is anything wrong with the second extension of protocol Exercise?
edited: the following is the code.
import Cocoa
protocol Exercise: CustomStringConvertible {
var name: String { get }
var caloriesBurned: Double { get }
var minutes: Double { get }
}
extension Exercise {
var caloriesBurnedPerMinute: Double {
return caloriesBurned / minutes
}
}
extension Exercise {
var description: String {
return "Exercise(\(name), burned \(caloriesBurned) calories in \(minutes) minutes)"
}
}
There is nothing wrong with your code, That is just Xcode 10's new feature. See here.
It's a way of running your code line by line, but there are some limitations. If you hover over the line number "20", you will see a grey line:
That means Xcode can't only run that part of the code, presumably because how Xcode handles extension declarations.
Just add some code that actually runs, as opposed to just declarations, and press the play button above the bottom panel. Your code will run just fine.
You need to wrap the Double variables in a String cast like String(caloriesBurned):
extension Exercise {
var description: String {
return "Exercise(\(name), burned \(String(caloriesBurned)) calories in \(String(minutes)) minutes)"
}
}
I don't know why, but it helps
This is my first project in Swift so please bear with me.
punkteLimit should be initialized with value 30. The value of the variable as well as a label should be updated everytime a slider value is changed.
var punkteLimit: Int = 30
#IBAction func sliderPunktelimitChanged(_ value: Float) {
punkteLimit = Int(value)
labelPunktelimit.setText("Punkte-Limit: \(punkteLimit)")
}
This seems to work fine. The label updates correctly, i.e. when I change the slider to 28, it says "Punkte-Limit: 28". However, punkteLimit is stuck at the initial value of 30 in the following part (the same is true for considerPunktelimit but the solution should be identical). The haptic feedback will be triggered at gesamtPunkte == 30 regardless of the changes above.
I use a button that performs gesamtPunkte += 1 to adjust the value, if it matters.
var gesamtPunkte: Int = 0 {
didSet {
if gesamtPunkte == punkteLimit && considerPunktelimit == true {
WKInterfaceDevice.current().play(WKHapticType.stop)
}
...
}
}
I'm not exactly sure where to go from here.
Help is much appreciated.
I solved the problem by moving the variable(s) in question outside of the InterfaceController class (making them global?). I have read mixed opinion about this approach, if anyone wants to comment on why it didn't work inside of the class and whether or not there are problems with making them global, feel free to.
I'm a long-time Objective-C user and slowly migrating towards Swift with new projects. I'm using CocoaPods for the bigger things and can't find a good library to cover this.
So I have this code inside my NSViewController viewDidLoad to start with:
_ = NSEvent.addGlobalMonitorForEventsMatchingMask(NSEventMask.KeyDownMask) {
(event) -> Void in
print("Event is \(event)")
}
let event = NSEvent.keyEventWithType(NSEventType.KeyDown,
location: CGPoint(x:0,y:0),
modifierFlags: NSEventModifierFlags(rawValue: 0),
timestamp: 0.0,
windowNumber: 0,
context: nil,
characters: "\n",
charactersIgnoringModifiers: "",
isARepeat: false,
keyCode: 0) //NSF7FunctionKey
NSApplication.sharedApplication().sendEvent(event!)
So the first event capturing works perfect after having my app checked in the System Preferences' Accessibility list. Anywhere in OS X it will capture key-presses. Now in the docs it says for Function-keys I should use keyEventWithType.
I found this gist and noticed that it addresses the same sharedApplication instance, yet I don't know how to catch the event. Do I delegate in a certain way? Also the F-key constant is int and the method says it only wants to receive Uint16. I can typecast it, but I guess I'm using it wrong.
Fixed it by using a CocoaPods pod that I found later. Works perfectly.