Post

Replies

Boosts

Views

Activity

How do you ensure one of your app's hotkeys isn't reserved?
I was just stymied by a bug report of a hotkey not working in my app that I couldn't reproduce. It turned out that Mission Control hijacks Ctrl-arrow hotkeys, but I have all that turned off on my system. How do you check a hotkey you're planning to use in your app against ones in use by the OS? A Web search on this issue turns up plenty of questions but no answers that I've seen. Another annoyance is that the menu bar showed that the hotkey was going to work.
0
0
702
Mar ’21
UIButton's setImage(_:for:) breaks "highlighted adjusts image"
My app has a lot of buttons that indicate their "on" state with a special image, assigned in Interface Builder to the Selected state. There's a different image assigned to the Default state, for "off." I found that when the user tapped a button that was "on," iOS insisted on redrawing it with the Default image. It turns out that Interface Builder misrepresents button states as exclusive: default highlighted selected disabled Wrong. For example, a button can be selected AND highlighted. That was the problem in my case, which you can solve programmatically by doing a union of states like this: thirdsButton.setImage(UIImage(named: "frame_guide_3x3"), for: UIControl.State.selected.union(.highlighted)) That actually does work... but it breaks "highlighted adjusts image," where iOS will dim the button slightly on contact. Now the user doesn't get any feedback upon pressing the button. Known defect?
0
0
840
Nov ’21
Xcode just added a bogus import statement to a source file by itself. WTH?
After a minor source-code change, my project wouldn't build anymore; Xcode raised dozens of errors complaining about a missing module and loads of other issues. Lately Xcode (13.1) has been spewing spurious errors on a regular basis, highlighting allegedly erroneous source lines with repeated instances of the same complaint... but declaring 'build succeeded" in the status bar at the top of the screen and running the app successfully. This is happening on two systems, one Intel and the other Apple Silicon. I've not found any explanation. Cleaning and deleting DerivedData don't fix it. So I've learned to ignore these "errors." But this time the build really was failing, so I looked at the first error. Xcode had inserted a line (into a years-old file) that attempted to import a nonexistent module. The name ("SwiftProtobufTests") appears in the package-definition file of a subproject (which builds Google protocol-buffer support in Swift). But it's not referred to or used anywhere, and I certainly didn't change anything in this source file related to it. Has anybody else had this happen? Xcode seems to have suffered from major regressions lately; it's barely stable enough to use right now. There are other insidious signs of internal problems. For example, when Xcode offers to "fix" an erroneous line (whether the error is real or not), it often inserts the fix into the wrong place in the text, garbling it and causing syntax errors. It also inserts missing cases in switch statements (after the "must be exhaustive" error) at the wrong level in the hierarchy, also causing an error. Again, this is happening on two systems, one a brand-new M1 Pro that was set up from scratch.
0
0
903
Dec ’21
Have you had a spurious build appear in App Store Connect / Testflight?
I had just uploaded a new build of my app and it had been processed. I went to submit it for beta testing, when I noticed another build with the next build number "processing." But I never submitted any such build. I went back to my project and double-checked the version number. It was what I expected it to be: one lower than this mysterious build that suddenly appeared. App Store Connect now shows that this mystery build is ready to be submitted. I'm the only developer on this app. Has anyone seen this before? Thanks!
0
0
742
Dec ’21
How are you supposed to test Mac apps that support Mac OS earlier than 12?
Our QA team is trying to test our application on all platforms we support, but Apple has inexplicably blocked installation of TestFlight on OS 11. Does anyone know the rationale behind this, or how we're supposed to distribute test builds in an orderly manner now? Having to make ad-hoc builds piecemeal and E-mail them around with duplicated instructions is not exactly professional. Thanks for any insight!
0
0
754
Jan ’22
How do you control the volume of ApplicationMusicPlayer?
I need to duck the audio coming from ApplicationMusicPlayer while playing a local file using AVAudioPlayer. I've tried using the duckOthers option as follows, but it doesn't work: let appAudioSession = AVAudioSession.sharedInstance() do { try appAudioSession.setCategory(.playAndRecord, mode: .default, options: .duckOthers) Maybe this is because there's one session for the entire app, and ApplicationMusicPlayer is using it? This is a fairly critical problem for my application, since Music content is always much louder than locally recorded content. Any insight appreciated.
0
0
694
Mar ’24
MacOS "Made for iPad" builds are not being updated by Xcode
I suddenly noticed that changes I made in code had no effect on the app when I rebuilt it and ran it on my M1 Mac as a "made for iPad" target. The debugger will even stop on new lines and seem to execute them, but they do nothing. If I clean the build folder and re-run, the same line executes as expected. This wastes an incredible amount of time until you discover what's happening. Now I have to remember to clean build folder every time I build and run. The application's structure is very simple, with no included libraries or third-party dependencies. Anybody else seeing this? Xcode 15.3 under Sonoma (14.4.1).
0
0
603
Apr ’24
All of a sudden Xcode says "Use of unknown directive #Preview" in SwiftUI
I work on my project on two computers. One of them is older and stuck at Xcode 13. My project targets iOS 15+. Previously I was able to bounce back and forth between the two, checking code into source control in between. After doing a bunch of work on one of them over an extended period, I've returned to my older one and checked out the code... only to be unable to build because Xcode balks at every use of #Preview. I didn't change any project settings in the meantime, so I have no idea why this is suddenly a problem... Edit: It turns out that this is because previous versions of the SDK did not use this macro. Because I created a couple of new SwiftUI files on the newer OS and Xcode/SDK, it plopped #Preview into the new files instead of the previous implementation, PreviewProvider. I'll leave this post up for anyone who searches on this problem, since I found zero other references in a general Web search.
1
2
2.7k
Dec ’23
Why would you use @State at the application level, or anywhere outside SwiftUI?
I am trudging through the doc on the seemingly endless ways to expose model data through a view hierarchy. The Apple doc here provides this example: struct BookReaderApp: App { @State private var library = Library() var body: some Scene { WindowGroup { LibraryView() .environment(\.library, library) } } } Why would you do this? Is the Library at risk of being repeatedly destroyed and re-created? Also, Library is defined as an Observable class, not a struct. So why is it @State and not @StateObject?
1
0
584
Dec ’23
Why is AVAudioRecorder creating corrupt files?
I'm attempting to record from a device's microphone (under iOS) using AVAudioRecorder. The examples are all quite simple, and I'm following the same method. But I'm getting error messages on attempts to record, and the resulting M4A file (after several seconds of recording) is only 552 bytes long and won't load. Here's the recorder usage: func startRecording() { let settings = [ AVFormatIDKey: Int(kAudioFormatMPEG4AAC), AVSampleRateKey: 22050, AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue ] do { recorder = try AVAudioRecorder(url: tempFileURL(), settings: settings) recorder?.delegate = self recorder!.record() recording = true } catch { recording = false recordingFinished(success: false) } } The immediate sign of trouble appears to be the following, in the console. Note the 0 bits per channel and irrelevant 8K sample rate: AudioQueueObject.cpp:1580 BuildConverter: AudioConverterNew returned -50 from: 0 ch, 8000 Hz, .... (0x00000000) 0 bits/channel, 0 bytes/packet, 0 frames/packet, 0 bytes/frame to: 1 ch, 8000 Hz, Int16 A subsequent attempt to load the file into AVAudioPlayer results in: MP4_BoxParser.cpp:1089 DataSource read failed MP4AudioFile.cpp:4365 MP4Parser_PacketProvider->GetASBD() failed AudioFileObject.cpp:105 OpenFromDataSource failed AudioFileObject.cpp:80 Open failed But that's not surprising given that it's only 500+ bytes and we had the earlier error. Anybody have an idea here? Every example on the Web shows essentially this exact method. I've also tried constructing the recorder with let audioFormat = AVAudioFormat.init(standardFormatWithSampleRate: 44100, channels: 1) if audioFormat == nil { print("Audio format failed.") } else { do { recorder = try AVAudioRecorder(url: tempFileURL(), format: audioFormat!) ... with mostly the same result. In that case the instantiation error message was the following, which at least mentions the requested sample rate: AudioQueueObject.cpp:1580 BuildConverter: AudioConverterNew returned -50 from: 0 ch, 44100 Hz, .... (0x00000000) 0 bits/channel, 0 bytes/packet, 0 frames/packet, 0 bytes/frame to: 1 ch, 44100 Hz, Int32
1
1
1.5k
Mar ’24
How do you pass a view builder into a view?
I'm making a custom control, specifically a checkbox next to a "label." I want the label parameter, like many in Apple's built-in controls, to take a view-building closure. But I can't figure out the correct syntax. I looked at the declaration of Apple's NavigationLink control for clues: public struct NavigationLink<Label, Destination> : View where Label : View, Destination : View { /// Creates a navigation link that presents the destination view. /// - Parameters: /// - destination: A view for the navigation link to present. /// - label: A view builder to produce a label describing the `destination` /// to present. public init(@ViewBuilder destination: () -> Destination, @ViewBuilder label: () -> Label) But when I mimic this, the compiler complains about the body() function: struct CheckboxItem<Label> : View where Label : View { let stateCheck: () -> Bool let label: () -> any View let boxSize: CGFloat init(withStateCheck: @escaping () -> Bool, boxSize: CGFloat, @ViewBuilder label: @escaping () -> Label) { stateCheck = withStateCheck self.label = label self.boxSize = boxSize } var body: some View { HStack { <-- ERROR: "Type 'any View' cannot conform to 'View'" Image(systemName: stateCheck() ? "checkmark.square" : "square") .resizable() .aspectRatio(contentMode: .fit) .frame(width: boxSize, height: boxSize) .foregroundColor(AppStyle.labelColor) .opacity(0.75) label() } } } Also, note that I had to put @escaping before my label parameter, but that's not seen in Apple's. Any ideas?
Topic: UI Frameworks SubTopic: SwiftUI
1
0
201
Mar ’25
Can't find any realistic example of how to use NavigationPath
Like many applications, mine involves navigation where the user starts a process on one screen and then progresses through several more steps to reach a conclusion. When he confirms that choice, I need to dismiss the entire stack. In my case, he's browsing contacts, selecting one, and then selecting a communication method from those offered by the contact. This still appears to be a PITA in SwiftUI. NavigationPath is supposed to provide a way to programmatically control a stack of views. Well... I can't find a single example of how to use it for this, except with absurdly shallow (as in a single level) of child views that all take the same datatype. Nowhere do I see how to use the path as users proceed through your view hierarchy with NavigationLinks. I have not seen any example of how elements get added to the path or how they are related to each added view. Nor can I find an example of popping views off the stack by removing related elements from the path. I created a class that encloses a NavigationPath: @Observable class NavPathController { var path: NavigationPath init() { path = NavigationPath() } func popOne() { path.removeLast() } func popAll() { path.removeLast(path.count) } } In my root view, I pass a binding to this controller's NavigationPath when creating the NavigationStack: @State private var viewStack = NavPathController() var body: some View { NavigationStack(path: $viewStack.path) { VStack() { NavigationLink(destination: UserFindingView(viewPathController: viewStack), label: { Text("Pick a recipient") }) } } And likewise each view passes the same view-path controller object to each child view that's invoked with a NavigationLink (instead of using an environment variable, because I find those hokey). But in the end, the path is empty; not surprisingly, clearing it does not pop the views. So how is one supposed to make this work?
Topic: UI Frameworks SubTopic: SwiftUI
1
0
197
Mar ’25
How do you put a self-signed certificate on iOS 17 simulator?
I have created certificates to test development locally with HTTPS. You used to be able to drag-&amp;-drop a certificate on the simulator, but this does not appear to work anymore. You can drag one onto the simulator and get the + drop symbol, but attempting to go into "VPN &amp; device management" to trust it under General settings just shows a blank screen that bounces you out immediately. Now what?
2
0
4.9k
Oct ’23