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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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?
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.
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!
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!
I'm not talking about the Music service (or MusicKit); I mean for adding functions to the desktop Apple Music software.
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?
My application targets iOS 15+. Attempting to build and run it on my iPhone SE (orphaned at iOS 15.6) results in "Failed to prepare the device for development."
I'm building with Xcode 15.2.
What is the expected procedure here?
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.
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).
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
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
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?
Given that SwiftUI and modern programming idioms promote asynchronous activity, and observing a data model and reacting to changes, I wonder why it's so cumbersome in Swift at this point.
Like many, I have run up against the problem where you perform an asynchronous task (like fetching data from the network) and store the result in a published variable in an observed object. This would appear to be an extremely common scenario at this point, and indeed it's exactly the one posed in question after question you find online about this resulting error:
Publishing changes from background threads is not allowed
Then why is it done? Why aren't the changes simply published on the main thread automatically?
Because it isn't, people suggest a bunch of workarounds, like making the enclosing object a MainActor. This just creates a cascade of errors in my application; but also (and I may not be interpreting the documentation correctly) I don't want the owning object to do everything on the main thread.
So the go-to workaround appears to be wrapping every potentially problematic setting of a variable in a call to DispatchQueue.main. Talk about tedious and error-prone. Not to mention unmaintainable, since I or some future maintainer may be calling a function a level or two or three above where a published variable is actually set. And what if you decide to publish a variable that wasn't before, and now you have to run around checking every potential change to it?
Is this not a mess?
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?