Post

Replies

Boosts

Views

Activity

SwiftUI Settings scene (Preferences): how call action when closed by user (click on red button or Cmd-W)
Hi, I thought this should be quite easy and maybe I only have tomatoes on my eyes, but I cannot find out how to call an action when the user clicks the red button or use CMD-W to close the Preferences window (= Settings Scene). I use Core Data. In the Preferences, many data structures, which define my system, are changed. I learned, that you shouldn't save too often to avoid performance problems, so now I want to save the Core Data context when the user closes the Preferences window. I tried .onDisappear, onChange of focus etc. but this didn't work. How can I define an action? Any hints are welcome :-)
2
0
1.3k
Apr ’22
SwiftUI CloudKit App crashes at start with "Unable to load nib file: MyApp, exiting"
I'm developing a SwiftUI App for macOS in Xcode 13.2. When I try to run the App in Xcode, I get this error messages in the console and the app terminates: 2021-12-28 13:13:21.680087+0100 MyAppProject[21343:363165] [CK] Giving up waiting to register for remote notifications 2021-12-28 13:13:23.548389+0100 MyAppProject[21343:362383] Unable to load nib file: MyAppStartViewName, exiting Until now, the error happend sporadically. Now I use a new MacBookPro with M1max and the error happens every time. As it is a SwiftUI App, there is no nib file at all. I didn't find any information about SwiftUI generating a nib file... How can I prevent the bug and get the App running? Any hints are welcome :-)
3
0
1.2k
Dec ’21
SwiftUI List crashes when removing a selected item
Hi, I have a severe problem with the SwiftUI List view in Xcode 12 (beta). When a List item, which is selected, is removed, the List crashes every time. "[General] Row 2 out of row range [0-1] for rowViewAtRow:createIfNeeded:" Looks like a bug in SwiftUI to me. What can I do to prevent the crash? I've tried several things already, but with no success. I'm stuck with this problem since 3 days now... Example code: // Example to reproduce bug // * Select no item or other than last item and press button: selection is reset, last item is removed, no crash // * Select last list item and press button "Delete last item" => Crash // import SwiftUI class MyContent: ObservableObject {     @Published var items: [String] = []     @Published var selection: Set<String> = Set()          init() {         for i in 1...5 {             self.items.append(String(i))         }     } } struct MyView: View {     @ObservedObject var content: MyContent = MyContent()     var body: some View {         VStack {             List(content.items, id: \.self, selection: $content.selection) {                 item in                 Text("\(item)")             }             Button("Delete last item", action: {                 if content.items.count > 0 {                     content.selection = Set()  // reset selection                     var newItems = Array(content.items)                     newItems.removeLast()                     content.items = newItems                 }             })         }     } }
8
0
2.6k
Sep ’20