This is still an issue—debug messages are not showing in Console.app, running macOS Sonoma 14.5 and Xcode 16.0 beta 4.
Xcode's own Console works fine.
Post
Replies
Boosts
Views
Activity
Apple confirmed that capturing group.id is the correct way to do it. They explained that the reason for that is because the predicate requires all captured values to be Codable and Sendable. And since Group is neither, it won't work and requires a local capture.
I haven't tested this further, as I am not actively exploring moving to iOS 17 at this point.
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
}
}
@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]
}
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.
Oh, for crying out loud, Apple! What is this?
Another half-baked feature, as if we didn't get enough of these already (SwiftUI, Mac Catalyst, Xcode previews, ...).
Seeing this in Xcode 12.4/iOS 14.4. Very annoying 😡🤬
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!