Post

Replies

Boosts

Views

Activity

In SwiftData when encoding/decoding Predicate, what's the reason for PredicateCodableConfiguration?
I'm converting a project that previously stored some NSPredicates as the string format. When converting to SwiftData I discovered Predicate is Codable, which makes things nice... except for PredicateCodableConfiguration. From what I understand you have to specify every model and key you use in the predicate or the encode/decode fails. This is kind of a pain, because you already define this in the Predicate. Does anyone know what the reason for this is? There's also PredicateCodableKeyPathProviding which lets you define the keys for a class all at once, which makes it slightly easier. But if SwiftData is intended to reduce boilerplate code, why does the Predicate itself not provide enough detail about what to encode/decode?
0
0
370
Sep ’23
iOS 17 beta, searchable suggested tokens disappear when query is not empty
In iOS 16, suggested tokens remain visible when the query updates. I use this guide the user on what to type for more advanced queries. (e.g. if they type backslash, I give them a list of supported commands to use that will be tokenized "hasImage: true" for example). In iOS 17, the suggested tokens disappear when the query is not empty. Does anyone know of a workaround? I've reported to Apple and hoping others are having this problem, so we can get it fixed before the betas are done. It does not appear that the value of the suggested tokens state is changing, just that they are no longer visible. Here's a minimum example, if you run on iOS 16 it runs as expected, on iOS17 it breaks struct ContentView: View { // MARK: Internal struct Token: Identifiable, Equatable { let text: String var id: String { text } } var body: some View { NavigationStack { List { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("Hello, world!") } VStack { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("Hello, world!") } } .navigationTitle("Search Suggestions") .searchable(text: $query, tokens: $tokens, suggestedTokens: $suggestions, placement: .toolbar, prompt: "Search") { token in Text(token.text) } } } // MARK: Private @State private var query: String = "" @State private var suggestions: [Token] = [Token(text: "One"), Token(text: "Two")] @State private var tokens: [Token] = [] }
1
1
917
Aug ’23