Post

Replies

Boosts

Views

Activity

Reply to navigationDestination with computed properties from SwiftData queries
it looks like I had left some test code in my List example I initially provided. The below code is what I'm actually using (no online filtering, I'm using the computed property) For the user todo lists section. // MARK: -- User TodoLists Section(header: Text("Lists").padding(.top, -24)) { ForEach(userTodoLists) { list in NavigationLink(value: list) { Text(list.name) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’24
Reply to SwiftUI not observing SwiftData changes
I still haven't figured out why this is happening. I'm moving forward with manually updating the arrays but would still like to understand if the SwiftData changes to the array are supposed to be picked up by SwiftUI. If so, then I can file a bug but I'm not sure how to tell if this is expected behavior or not.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’24
Reply to SwiftUI: Command SwiftCompile failed with a nonzero exit code
I have done some additional testing. Since all of the Archive compiler errors I'm getting now exist within the #Preview macros used in the Views I removed them all. Once I deleted all of the #Preview macros in the app I could delete the SampleData.swift and PreviewContainer.swift files that the compiler wasn't finding. Now those files don't exist and I can continue to build and run the app normally. However Release build still fail with the same compiler error and the Archive command fails with the same Command SwiftCompile failed with a nonzero exit code build error. Looking at the log (here) it looks like the same result as my Release builds - no details. I don't understand why Archive was failing to build with all the #Preview macros - I'll have to circle back around and look at that later. At the moment though, both Release builds and Archive is failing with the same nonzero exit code failure.
Nov ’24
Reply to SwiftUI: Command SwiftCompile failed with a nonzero exit code
I have been able to fully reproduce this issue in a sample app. The following code will build, and run on both a simulator and a device. It will also work in XCode preview. When I attempt to archive it or run a Release config, it fails with the nonzero error. import SwiftUI class MyModel { var name: String var children: [MyModel] = [] init(name: String) { self.name = name } } struct MyModelPicker: View { private var items: [MyModel] = [] init() { let foo = MyModel(name: "Foo") let bar = MyModel(name: "Bar") let people = MyModel(name: "People") let johnDoe = MyModel(name: "John Doe") let maryJane = MyModel(name: "Mary Jane") let childDoe = MyModel(name: "Child of Doe") johnDoe.children.append(childDoe) people.children.append(contentsOf: [ johnDoe, maryJane ]) foo.children.append(bar) items = [ foo, people ] } var body: some View { List { ForEach(items, id: \.name) { item in getRowForUserList(item) } } } @ViewBuilder func getRowForUserList(_ list: MyModel) -> some View { if list.children.isEmpty { Text(list.name) } else { getRowForParent(list) } } @ViewBuilder func getRowForParent(_ list: MyModel) -> some View { DisclosureGroup(isExpanded: .constant(true)) { ForEach(list.children, id: \.name) { child in getRowForUserList(child) } } label: { Text(list.name) } } } struct ContentView: View { var body: some View { VStack { MyModelPicker() } } } #Preview { ContentView() } With this reproducible, I submitted bug report FB15926480 with this example project included. Within the getRowForParent function there is the following loop: ForEach(list.children, id: \.name) { child in getRowForUserList(child) } Commenting out the getRowForuserList function call will allow archiving to complete successfully. It seems to be an issue with recursion of the views.
Nov ’24
Reply to SwiftUI: Command SwiftCompile failed with a nonzero exit code
After some additional debugging, I have found that replacing the usage of @ViewBuilder with dedicated structs allows for archive builds to be created. I can copy the implementation of each ViewBuilder as-is with no changes and past them into structs. Release configuration and Archiving compiles successfully. The revised code is below - again with no implementation changes other than pulling the code out of ViewBuilder and into a struct. import SwiftUI @Observable class MyModel { var name: String var children: [MyModel] = [] init(name: String) { self.name = name } } struct MyModelPicker: View { private var items: [MyModel] = [] init() { let foo = MyModel(name: "Foo") let bar = MyModel(name: "Bar") let people = MyModel(name: "People") let johnDoe = MyModel(name: "John Doe") let maryJane = MyModel(name: "Mary Jane") let childDoe = MyModel(name: "Child of Doe") johnDoe.children.append(childDoe) people.children.append(contentsOf: [ johnDoe, maryJane ]) foo.children.append(bar) items = [ foo, people ] } var body: some View { List { ForEach(items, id: \.name) { item in RowView(list: item) } } } } struct RowView: View { @Bindable var list: MyModel var body: some View { if list.children.isEmpty { Text(list.name) } else { ParentRowView(list: list) } } } struct ParentRowView: View { @Bindable var list: MyModel var body: some View { DisclosureGroup(isExpanded: .constant(true)) { ForEach(list.children, id: \.name) { child in RowView(list: child) } } label: { Text(list.name) } } } struct ContentView: View { var body: some View { VStack { MyModelPicker() } } } #Preview { ContentView() } I have updated my bug report to indicate this. It seems this is an issue with @ViewBuilder being able to recursively construct views.
Nov ’24
Reply to Xcode 26 - New Swift 6.2 Concurrency Sendable Closure Problems
I too, am running into this problem. I have a full reproducible example for something that works in XCode 16.4 but does not work in XCode 26, Beta 1. protocol TestProtocol:Sendable { var version: Int { get } } actor TestManager { private let migrations: TestProtocol init(migrations: TestProtocol) { self.migrations = migrations if migrations.version < 5 { } } func doSomething() async throws { if migrations.version < 5 { } } } This gives me: Main actor-isolated property 'version' can not be referenced from a nonisolated context; this is an error in the Swift 6 language mode I can store the property, then await the value before my check - which I guess is fine... func doSomething() async throws { let ver = await migrations.version if ver < 5 { } } Though this is a PITA when doing logging all over the app, or constantly accessing members of the object itself. For example, the attached screenshot shows I can't access version - despite the fact that the DatabaseMigration protocol is Sendable. Even more confusing for me is that I await a call to migration.build() and yet I still can't access member variables on the results of the awaited function... If I run this code in XCode 16.4, there's no actor-isolated warnings for Swift 6, even on a file->new project. I can't tell if this is a bug in XCode 26, or not. If it's not, I don't know what the expected developer workflow is for this going forward.
Topic: UI Frameworks SubTopic: AppKit Tags:
Jun ’25