Posts

Post not yet marked as solved
0 Replies
260 Views
I've a non-document based single window (mostly) SwiftUI app. In my observable app state class an undo manager is defined and changes are registered using that manager. This has not been a problem in the past. But now... 1st is a bug reported in FB13708788. I've replaced the macOS undo/redo with code that references the UndoManager I created. The menu does not reflect the current undo status. This is easily duplicated in a small app submitted with the feedback. 2nd issue is hit or miss. Sometimes selecting Undo via the menu or the keyboard invokes undo multiple times. This is rare when running the app, but it has happened. On the other hand undo is always invoked multiple times when running an XCUITests. A little logging shows the invocations are quite close together. Undo invoked at 2024-04-05 13:14:19.975570-0700 Undo invoked at 2024-04-05 13:14:19.975768-0700 Calls were only 198 microsec apart. The test makes a change, makes a second change, then tried to undo the second change. Both changes are undone. But not (usually) if I perform the exact steps by hand instead of as an XCTest. Any ideas on how I might track down the cause? Mac Studio M2 Max running 14.4.1.
Posted
by marchyman.
Last updated
.
Post not yet marked as solved
4 Replies
424 Views
If I drag something into my SwiftUI Mac app the .dropDestination gets an array of URLs that I can do with what I want. If I use .fileImporter to get an identical array of URLs I should wrap start/stop securityScopedResource() calls around each URL before I do anything with it. Can anyone explain the logic behind that? Is there some reason I'm not seeing? It is especially annoying in that the requirement for security scoping also doesn't exist if I use an NSOpenPanel instead of .fileImporter.
Posted
by marchyman.
Last updated
.
Post marked as solved
10 Replies
1.9k Views
I have a performance issue with a Mac SwiftUI app. Using instruments I see hangs reported. When I zero in on a hang I see that the time profiler reports most of the hang -- in one example 658 out of 687 ms -- being in 'static AppName.$main() [inlined]'. I think that is saying my app is busy, but busy doing what? The "hangs" are related to SwiftUI table processing. User experience is something like this: select an item, see the view changes based upon selection show up a second or two later. The duration of the hang increases with the number of items in the table. I'm testing with 100 ~ 1200 table entries.
Posted
by marchyman.
Last updated
.
Post marked as solved
5 Replies
1k Views
Has anyone else created a macOS SwiftUI app that uses a Table with a largish (~1000) number of entries? My app works OK at about 100 entries, but slows down as the number of entries increase. How slow? An instrumented test with 1219 entries shows a Hang of over 13 seconds from simply clicking/selecting an item in the table. Instruments says the time is mostly spent in _CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION. Digging deeper I see AG::Subgraph::update(unsigned int) and descendants account for about half of the hang time. My app is using @Observable on macOS 14 and is being tested on an M2 Max Studio. There are other reported hangs. All seem to be in Swift/SwiftUI code.
Posted
by marchyman.
Last updated
.
Post not yet marked as solved
0 Replies
304 Views
SwiftUI Table on macOS with two columns. In some test code the items being sorted are: @Observable final class Item: Identifiable { let id: Int var displayId: String { String(id) } let description: String init(_ id: Int) { self.id = id self.description = UUID().uuidString } } The table columns are displayId and description. The Tables initial sort order is defined by this descriptor: var sortOrder = [KeyPathComparator(\Item.description)] The strangeness is this: the sorted description order is very strange. "0B5..." sorts before "0B0..." ? Or if I reverse the sort order I get this: "AA..." before "FF..." What am I missing? Sorting the first column does what I'd consider to be the right thing, showing the column in numerical order even though I'm using the String representation of id.
Posted
by marchyman.
Last updated
.
Post marked as solved
1 Replies
998 Views
In the initial Xcode 15/iOS 17 Beta selecting a Marker would give a visible indication that the marker was selected without setting the selection. This is the code I used. struct ContentView: View { let location = CLLocationCoordinate2D(latitude: 37.0, longitude: -122.0) @State private var position: MapCameraPosition = .automatic @State private var selectedItem: MKMapItem? var body: some View { VStack { Text(selectedItem == nil ? "Nothing Selected" : selectedItem?.name == nil ? "No name" : selectedItem!.name!) .bold() .padding() Map(position: $position, selection: $selectedItem) { Marker("Marker", coordinate: location) .tag(1) .tint(.red) } } .padding() } } I submitted feedback and things changed in Beta 3. Now I can not select the Marker. That's not the direction I'd hoped to see. Am I doing something wrong or is there no way to select a Marker placed on a map?
Posted
by marchyman.
Last updated
.
Post not yet marked as solved
0 Replies
699 Views
Is there a SwiftUI TableView equivalent to the NSTableViewDelegate method tableView(_: TableView, selectionIndexesForProposedSelection: IndexSet) -> IndexSet method? I've a table of items but some of the items should not be selectable.
Posted
by marchyman.
Last updated
.
Post not yet marked as solved
0 Replies
570 Views
A UI test opens program preferences and clicks on a path item. That results in an open dialog box. So far so good. I used to be able to simulate shift-command-G which gave me a sheet I could use to enter a known test path. That stopped working, either with Xcode 13 or with macOS Monterey. Or perhaps earlier. Shift-command-G opens something. It isn't a sheet or it is some new kind of sheet. The problem is I can not see any matching UI element in the Application tree of elements. Recording a test doesn't work, either. Interaction with the element is not recorded. What is this element? Can it be manipulated with XCode UI tests?
Posted
by marchyman.
Last updated
.