Post

Replies

Boosts

Views

Activity

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
861
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
915
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
755
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
764
Jan ’22
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-&-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 & device management" to trust it under General settings just shows a blank screen that bounces you out immediately. Now what?
2
0
5.0k
Oct ’23
How do we install older iOS SDKs in Xcode?
Hi all. I'm writing an app that targets iOS 15 and beyond. I can't build or test because Xcode complains that iOS 17 SDK is not installed, which is true. But my deployment target is set for 15.6. I installed a simulator for 15 by downloading iOS 15 simulator support from the Platforms tab in settings. This is also where you see that iOS SDKs there are... but there's no way to add them. The + button in the corner only lets you install more simulators. Where do you install support for earlier iOS versions? This is in Xcode 15.0.1. Thanks.
2
4
2.1k
Oct ’23
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
603
Dec ’23
SwiftUI seems to assume that no one uses optionals anymore.
I'm wrestling with a view that handles a class whose members are mostly optional. This does not appear to be a scenario that SwiftUI envisions. What is the expected approach? Take this class, for example, which represents a user: class User : Equatable, Codable, ObservableObject { var ID: String? var pw: String? var username: String? var firstName: String? var lastName: String? var EMail: String? var phoneNbr: String? var avatarURL: String? var mediaServiceID: String? var validated: Bool = false ... } I can't directly show a form to fill this thing out in SwiftUI, because you can't bind text fields to optionals. Most of the published workarounds to that involve using let to create a non-optional variable if the member isn't nil; but this is unworkable because that won't populate a nil member if someone enters text in the text field. Apple docs talk about custom binding, which would probably work to populate an optional member. That means doing this in the SwiftUI view to set the object's username, for example: @State private var tempUser = User() private var username: Binding<String> { Binding { if let theName = tempUser.username { return theName } else { return "" } } set: { newName in tempUser.username = newName } } But that means setting up one of these verbose methods for every single optional member of every class I want to show in a UI. At that point I might as well just make a shadow structure that's all non-optionals that I can bind directly to. Or just make all the members non-optional and just face the fact that optionals are done with in the age of SwiftUI. Or is there some succinct approach I'm missing here? Thanks for any insight.
2
1
1.3k
Jan ’24
Are changes to published embedded objects really not detected in SwiftUI?
Let's say I have a class to represent a user: class User : Equatable, Codable, ObservableObject { @Published var ID: String = "" @Published var username: String = "" @Published var firstName: String = "" @Published var lastName: String = "" @Published var EMail: String = "" @Published var phoneNbr: String = "" @Published var avatarURL: String = "" @Published var mediaServiceID: String = "" @Published var validated: Bool = false ... } I also have a controller ("viewmodel") to broker interactions between SwiftUI views and the User. It contains a User object as: @MainActor class UserManager : ObservableObject { @Published var user: User ... } And finally of course the view, into which I pass the UserManager upon initialization: struct StartupView: View { @ObservedObject var userMgr: UserManager ... } Changing published members of the User embedded in UserManager does not trigger a UI refresh. That strikes me as broken, since everything is published. Is it expected behavior?
3
0
946
Jan ’24
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
714
Mar ’24
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
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?
Replies
0
Boosts
0
Views
861
Activity
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.
Replies
0
Boosts
0
Views
915
Activity
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!
Replies
0
Boosts
0
Views
755
Activity
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!
Replies
0
Boosts
0
Views
764
Activity
Jan ’22
Why isn't TestFlight available for previous OSes?
Our application is available for current and previous generations of Mac OS. But our QA team can't test it, because Apple has inexplicably blocked previous OSes from TestFlight. Does anyone have an explanation for this idiotic policy?
Replies
0
Boosts
0
Views
1.1k
Activity
Apr ’22
Is there a plug-in SDK for the desktop Apple Music app?
I'm not talking about the Music service (or MusicKit); I mean for adding functions to the desktop Apple Music software.
Replies
0
Boosts
0
Views
663
Activity
Aug ’23
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?
Replies
2
Boosts
0
Views
5.0k
Activity
Oct ’23
How do we install older iOS SDKs in Xcode?
Hi all. I'm writing an app that targets iOS 15 and beyond. I can't build or test because Xcode complains that iOS 17 SDK is not installed, which is true. But my deployment target is set for 15.6. I installed a simulator for 15 by downloading iOS 15 simulator support from the Platforms tab in settings. This is also where you see that iOS SDKs there are... but there's no way to add them. The + button in the corner only lets you install more simulators. Where do you install support for earlier iOS versions? This is in Xcode 15.0.1. Thanks.
Replies
2
Boosts
4
Views
2.1k
Activity
Oct ’23
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.
Replies
1
Boosts
2
Views
2.7k
Activity
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?
Replies
1
Boosts
0
Views
603
Activity
Dec ’23
Apple doc still refers to nonexistent info.plist. Should we use the entitlements file instead?
I encountered this in Apple's doc: Users must grant permission for your app to access their music data. Add the NSAppleMusicUsageDescription key to your app’s Info.plist file Info.plist is no longer generated as part of Xcode projects. Do we add a key like this to the app's .entitlements file instead?
Replies
2
Boosts
0
Views
880
Activity
Jan ’24
SwiftUI seems to assume that no one uses optionals anymore.
I'm wrestling with a view that handles a class whose members are mostly optional. This does not appear to be a scenario that SwiftUI envisions. What is the expected approach? Take this class, for example, which represents a user: class User : Equatable, Codable, ObservableObject { var ID: String? var pw: String? var username: String? var firstName: String? var lastName: String? var EMail: String? var phoneNbr: String? var avatarURL: String? var mediaServiceID: String? var validated: Bool = false ... } I can't directly show a form to fill this thing out in SwiftUI, because you can't bind text fields to optionals. Most of the published workarounds to that involve using let to create a non-optional variable if the member isn't nil; but this is unworkable because that won't populate a nil member if someone enters text in the text field. Apple docs talk about custom binding, which would probably work to populate an optional member. That means doing this in the SwiftUI view to set the object's username, for example: @State private var tempUser = User() private var username: Binding<String> { Binding { if let theName = tempUser.username { return theName } else { return "" } } set: { newName in tempUser.username = newName } } But that means setting up one of these verbose methods for every single optional member of every class I want to show in a UI. At that point I might as well just make a shadow structure that's all non-optionals that I can bind directly to. Or just make all the members non-optional and just face the fact that optionals are done with in the age of SwiftUI. Or is there some succinct approach I'm missing here? Thanks for any insight.
Replies
2
Boosts
1
Views
1.3k
Activity
Jan ’24
Are changes to published embedded objects really not detected in SwiftUI?
Let's say I have a class to represent a user: class User : Equatable, Codable, ObservableObject { @Published var ID: String = "" @Published var username: String = "" @Published var firstName: String = "" @Published var lastName: String = "" @Published var EMail: String = "" @Published var phoneNbr: String = "" @Published var avatarURL: String = "" @Published var mediaServiceID: String = "" @Published var validated: Bool = false ... } I also have a controller ("viewmodel") to broker interactions between SwiftUI views and the User. It contains a User object as: @MainActor class UserManager : ObservableObject { @Published var user: User ... } And finally of course the view, into which I pass the UserManager upon initialization: struct StartupView: View { @ObservedObject var userMgr: UserManager ... } Changing published members of the User embedded in UserManager does not trigger a UI refresh. That strikes me as broken, since everything is published. Is it expected behavior?
Replies
3
Boosts
0
Views
946
Activity
Jan ’24
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.
Replies
0
Boosts
0
Views
714
Activity
Mar ’24
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
Replies
1
Boosts
1
Views
1.5k
Activity
Mar ’24