Post

Replies

Boosts

Views

Activity

Reply to SwiftData #Predicate cannot test for nil relationship
I did a bit more experimenting. The problem doesn't seem to be in the optionality of the types per se, as even the following doesn't work: @Model final class Item { var timestamp: Date var group: Group } @Model final class Group { var name: String var items: [Item] } What does work is comparing the objects' IDs: This works: func query(group: Group) { let id = group.id let predicate = #Predicate<Item> { item in item.group?.id == id // Compiles } } However, if the id is not in a local variable, the Predicate macro doesn't compile: func query(group: Group) { let predicate = #Predicate<Item> { item in item.group?.id == group.id // Doesn't compile } }
Sep ’23
Reply to SwiftData #Predicate cannot test for nil relationship
@newwbee Can you please show your code? I have just tested and neither of those variations (where you put the inverse) work: @Model final class Item { var timestamp: Date @Relationship var group: Group? } @Model final class Group { var name: String @Relationship(inverse: \Item.group) var items: [Item] } @Model final class Item { var timestamp: Date @Relationship(inverse: \Group.items) var group: Group? } @Model final class Group { var name: String @Relationship var items: [Item] }
Sep ’23
Reply to SwiftData #Predicate cannot test for nil relationship
Still an issue with the final release of iOS 17. Given the following models (initializers omitted for brevity): @Model final class Item { var timestamp: Date var group: Group? } @Model final class Group { var name: String var items: [Item] } This predicate doesn't compile: func query(group: Group) { let predicate = #Predicate<Item> { $0.group == group } } Force-unwrapping doesn't work either: $0.group! == group.
Sep ’23
Reply to A command modifying SceneStorage property for currently focused window (on macOS)?
I just spent half a day struggling with a similar issue 🤬 I, too, read the other thread where an Apple engineer posted a sample. I have finally found a solution based on this GitHub repo: https://github.com/jbmorley/swiftui-focus-demo That repo provides a view modifier that installs a background NSView, which can become the first responder for the window. Then this works: Text("Message: \(message.text)")             .frame(width: 200, height: 200)             .acceptsFirstResponder(isFirstResponder: $isFirst)             .focusedValue(\.message, $message) Note that focusedValue() has to be after the acceptsFirstResponder! Dear Apple, if you're reading this—please focus on documentation and samples for the next WWDC! And while at it, please try using some of your own technologies. Try writing a complete application in SwiftUI (just the ColorPicker is not enough). Thank you!
Jan ’21