Post

Replies

Boosts

Views

Activity

Is there a good reference for SwiftUI?
While I appreciate the work that Apple puts into the developer documentation, I find it very hard to use. Among other things, I'm looking for a reference (free / paid / online / dead tree) that describes the views available in SwiftUI with the applicable view modifiers and examples of how to use them.
2
0
955
May ’22
Do I have to be a paid developer to develop MacOS programs for personal use?
I am currently working with XCode 13.3.1 on OSX Monterey 12.3.1 on a Mac Mini M1. I have written some programs in Swift for personal use using a personal team certificate. I haven't paid the $99. Every couple of weeks or so, some of my programs will pop up a message saying "This Program Could Harm Your Mac" and won't let me run it when I try to launch them. It seems I have to recompile it and then it will work for a few more weeks. Other programs have run for several months. The programs are using Sandbox and Hardened runtime. Someone suggested that I try compiling the program without a certificate. I did that last night and the program ran. But this morning when I launched the program, I got a message that the program had unexpectedly quit. The "report" message said something about a code signature. FWIW, I am copying the program to my Applications folder.
5
0
3.0k
May ’22
Why is NSHostingView being laid out reentrantly?
func zoomOne() { region.span.latitudeDelta = 10_000 region.span.longitudeDelta = 10_000 } func zoomIn() { region.span.latitudeDelta /= 2 region.span.longitudeDelta /= 2 } func zoomOut() { region.span.latitudeDelta *= 2 region.span.longitudeDelta *= 2 } My MacOS app has three methods for adjusting the zoom on a MapKit map display. Each is tied to a separate view Button. zoomIn() and zoomOut() work as expected, but when the program calls zoomOne(), Xcode breaks and reports a runtime issue in the Issue Navigator: NSHostingView is being laid out reentrantly while rendering its SwiftUI content. This is not supported and the current layout pass will be skipped. As a fix, I tried embedding the zoomOne() region update in a DispatchQueue.main.async closure, but it still failed with the same issue. Thanks, Mark
0
1
1.4k
May ’22
Is there a way to Show Hide a sidebar with a button?
.commands{ SidebarCommands() } If I add the above to a MacOS app, the program gains a Show Sidebar / Hide Sidebar menu option on the View menu. I'd like to add a button to show or hide the sidebar such as the one in Xcode, but I can't find a way to do it? I would have thought that there would be a simple framework call, but my internet searches haven't turned up anything. I also like the way that Xcode places the Hide Sidebar button on the sidebar, but when the sidebar is hidden, the Show Sidebar button is on the left side of the window. Has any one figured out how to do this with SwiftUI?
2
0
3.4k
May ’22
Reduce CPU usage by MapAnnotations?
I have an app that displays a MapKit map with a Text as an a MapAnnotation. When the map is first displayed, the map is centered on the coordinates of the MapAnnotation and once things settle down, the CPU usage reported by Xcode's Debug Navigator goes to 0%. If the map is dragged or zoomed so that the MapAnnotation is not at the center, the CPU usage goes up during the motion, but does not go back to 0%, but settles down to a few per cent. If you look closely at the map, you can sometimes see that the MapAnnotation is vibrating. Other map features do not appear to move. I assume that the MapAnnotation is not tied to a fixed map location as are the map features and if the MapAnnotation is not at the center, its display position needs to be constantly recalculated.
0
0
771
May ’22
How to keep a Settings scene from slowing a Mac app?
I have a MacOS app that displays a MapKit Map on the main scene. The user can drag the map around with the mouse and the motion is smooth, until I enable the Settings scene. With the Settings scene enabled, the map doesn't follow the mouse but moves when the mouse is released. If I replace the Settings scene with a "Hello, World" view, the map dragging is fine. var body: some Scene { WindowGroup { LicenseLookupView(fccData: fccData) .navigationTitle(title) } Settings { FCCDatabaseSettings(fccData: fccData) } } I put a print statement in the constructor to the Setttings scene and the program prints multiple times as the map is dragged, so it appears that even though the Settings scene is not displayed to the user, it is being recreated every time the main Scene is updated. Is there a way to keep that from happening and only build the Settings scene when it is going to be shown to the user? As a comparison, the Preferences... dialog for Xcode is complex, yet it doesn't impact the performance of the app. Of course, Xcode may not be written in SwiftUI. Thanks in advance, Mark
1
0
670
May ’22
What is causing this error?
I used the Xcode template to create a Mac App. I then modified ContentView.swift import SwiftUI import MapKit struct ContentView: View {     @State private var region = MKCoordinateRegion( center: CLLocationCoordinate2D( latitude: 0.0, longitude: 0.0), span: MKCoordinateSpan( latitudeDelta: 0.5, longitudeDelta: 0.5))     var body: some View {         Map(coordinateRegion: $region) } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } When I run this code, Xcode reports a runtime error: Modifying state during view update, this will cause undefined behavior. It is reported on Thread 1. This is identified with a purple warning in the issue navigator, but there is no indication of the location of the error in the source code editor. The actual map coordinates don't matter. I get the same error with different coordinates. Xcode 13.3.1 OSX Monterey 12.3.1 Mac Mini M1 P.S. When I cut the example code above from Xcode and pasted it into this message, it added extra line breaks between each line (which I manually removed). Is there a way to have the code paste as it was in Xcode? P.P.S. When I listed the software and hardware info, If I don't make it a bulleted list, the ended up being displayed on one line. If I put blank lines between them, the blank lines are displayed. Is there any way to make a vertical list without bullets?
4
0
2.9k
Apr ’22
Why is MapKit CPU usage higher with SwiftUI than AppKit?
I've copied a couple of tutorial Mac OS apps using MapKit. One uses SwiftUI, the other AppKit. Both initially display a map and allow the user to pan and zoom with the mouse. According to XCode's debug navigator, once the user has stopped panning or zooming, the CPU usage goes to 0%. Both apps allow the user to enter a location and add a MapAnnotation to the map. On the AppKit version, once the annotation is added, the CPU usage drops back to 0%, but on the SwiftUI version, the CPU usage remains around 5 - 15%. If you look closely at the SwiftUI version, you can see the annotation vibrating by a pixel or so on the display. It seems to me that the display is being constantly updated. If the annotation is removed, the CPU usage goes back to 0% I placed a breakpoint in the code that draws the annotation in the SwiftUI version. When adding an annotation, the breakpoint is hit twice, but then no more, so I don't think the CPU is spending time in the Swift code. Xcode 13.3.1 OSX Monterey 12.3.1 Mac Mini M1
0
0
635
Apr ’22
How to add an exception to Sandbox?
My MacOS program is printing a message in the terminal window in XCode networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception. How do I do this? I don't see a way to add arbitrary File Access on the Signing & Capabilities tab under app setup. XCode 13.3.1 OSX Monterey 12.3.1 Mac Mini M1
6
2
8.0k
Apr ’22
Are there application classes where UIKit is a better choice than SwiftUI?
I am developing a Mac app that will control an external device (an amateur radio transceiver). The device is connected via ethernet and continually sends data describing various parameters. The display needs to continually update as these parameters change. I have partially executed this in SwiftUI using the Combine Framework to update views My issue is that with my understanding of SwiftUI, whenever a view is updated, SwiftUI recreates sibling views. So for example, if there is a stack with 2 views each corresponding to a different parameter, when one of the parameters is updated, both views are recreated. This isn't a problem with 2 views, but what if there are a large number of parameters (and views). Is there a way to design the app so that only the view for an individual parameter is recreated? The app would be designed such that the size of a view never changed, so the sibling views would not be moving. Or am I misunderstanding how SwiftUI works? Would UIKit be better suited for this, or does it also need to reevaluate constraints (or something else) each time a single view updates? Another issue I haven't been able to figure out with SwiftUI is how to have multiple windows. I'd like to have separate windows for related sets of parameters that the user can open or close and position on the screen as desired. The best I've been able to find in SwiftUI is different windows for different "documents" where the documents are similar to each other. Thanks in advance for any advice. Mark
2
0
488
Apr ’22
CoreAudio Project Posted to Github
I have posted a learning project on github. I have gone through the book "Learning Core Audio" by Adamson & Avila and converted the examples from Objective-C to Swift 5. I hope that this helps others trying to learn CoreAudio and if anyone sees issues in my code, please let me know. Thanks, Mark
0
0
1.2k
Apr ’22
Is there a bug in Developer Help in XCode 13?
With a recent update to XCode 13, something has happened to Developer Help. I am running two identical monitors on my development machine, a M1 Mac Mini (XCode 13.2, OSX 12.3.1) On most apps, if you hold the mouse button down on the green dot button at the top left of the window, there is a dropdown that gives choices: Enter Full Screen Tile Window to Left of Screen Tile Window to Right of Screen Move to CB282K(1) CB282K(1) refers to one of my monitors that is set up as extended display. CB282K(2) is the other one, set up as main display, the one currently displaying the window. Usually, selecting the Move to CB282K(1) option moves the window to the other monitor. This works for most apps, including Xcode. But, if I bring up Developer Help, selecting this option does not move the Developer Help window. If, I manually drag the Developer Help window to the other monitor and select the Move to CB282K(2) option, it moves back to the main monitor. If I then select Move to CB282K(1) the Developer Help window will move and continues to move between monitors as needed. After closing the Developer Help window, if I open it again, it again refuses to move the second monitor until being dragged manually. As I said, I think this used to work. Has anyone else seen this behavior and is there some setting I can change to get it working again? Also, while not relevant to the question, is there a way to change the name of the monitor that shows up in the list. Is there a way I can change the menu to have options "Move to Extended Display" and "Move to Main Display"? Thanks, Mark
0
0
320
Apr ’22
How to set a breakpoint in library code?
When running my code, I got the following messages in the console: malloc: *** error for object 0x16fdfee70: pointer being freed was not allocated malloc: *** set a breakpoint in malloc_error_break to debug I understand the first message is coming from a bug in my code. The second is trying to help me figure out the issue. The question is how do I set this helpful breakpoint? FWIW, I've seen similar "set a breakpoint in ..." messages before in other cases.
1
0
2.5k
Apr ’22