Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Preview crashes on simple code
"padding()" should be ".padding()" As in: struct ContentView: View { var body: some View { VStack { Text("Hello, world!") .padding() Text("Another Line") } } } "padding()" is an instance method, so calling it without the leading ".", as you do, probably causes something horrible to happen, which causes the crash. (Since it will return a function, not a View)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Can I use api `UIApplicationVolumeUpButtonDownNotification` for getting volume up/down button?
AVAudioSession has a property "outputVolume". You could look for changes to this, using Key-value observing... ...and use that to trigger your photo. That might go against rule 2.5.9, but since Apple's Camera app uses the volume buttons, I think it should be okay. (Note: this technique does not work in the Simulator, it needs a real device) Perhaps something like this: import AVFAudio class VolumeButtonObserver { let audioSession = AVAudioSession.sharedInstance() var outputVolumeObservation: NSKeyValueObservation? init() { observeVolumeButtons() } func observeVolumeButtons() { do { try audioSession.setActive(true) } catch {} outputVolumeObservation = audioSession.observe(\.outputVolume) { (audioSession, changes) in print("A volume button was pressed") /// Take action here... } } }
Jan ’22
Reply to iMac can’t recognize Logitech keyboard and mouse on login
Yes this seems to be a problem, where certain bluetooth devices are not recognized, before logging in. Which makes it difficult to login! I had a recent trauma with this, when booting in Recovery mode... I had to dig out an ancient wired mouse. I will be interested to see if anyone has a solution to this. iMac Pro MK Anywhere 2 mouse Wired keyboard (to get round this issue!)
Topic: App & System Services SubTopic: Hardware Tags:
Jan ’22
Reply to Pass a Timer through Controllers
I also wish for the user to be able to close the app and have the timer run in the background The timer will not run in the background, but here is a technique that you could use: Add a mechanism to detect when the app is entering the background, or foreground On backgrounding: If your timer is live... Convert it to a notification (calculate the fire date from the timer expiry) Cancel the timer If the timer expires while the app is backgrounded, the user will see the notification On foregrounding: Remove pending notifications Restart the timer, if it has not expired
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’22
Reply to import pdf from url
PDFDocument(url:) returns an Optional value... Try this: func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { guard let url = urls.first else {         print("Error: no url") return } guard let dokument = PDFDocument(url: url) else { print("Error: could not create PDFDocument from url: \(url)") return } dokumnetpdf = dokument }
Jan ’22
Reply to import pdf from url
It looks like a permissions issue. Try this: func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { guard let url = urls.first else { print("Error: no url") return } guard url.startAccessingSecurityScopedResource() else { print("Error: could not access content of url: \(url)") return } guard let dokument = PDFDocument(url: url) else { print("Error: could not create PDFDocument from url: \(url)") return } dokumnetpdf = dokument }
Jan ’22