Post

Replies

Boosts

Views

Created

SwiftData iCloud AttributedString Platform Color compatibility
Hi Given a simple multiplatform app about Mushrooms, stored in SwiftData, hosted in iCloud using a TextEditor @Model final class Champignon: Codable { var nom: String = "" ../.. @Attribute(.externalStorage) var attributedStringData: Data = Data() var attributedString: AttributedString { get { do { return try JSONDecoder().decode(AttributedString.self, from: attributedStringData) } catch { return AttributedString("Failed to decode AttributedString: \(error)") } } set { do { self.attributedStringData = try JSONEncoder().encode(newValue) } catch { print("Failed to encode AttributedString: \(error)") } } } ../.. Computed attributedString is used in a TextEditor private var textEditorView: some View { Section { TextEditor(text: $model.attributedString) } header: { HStack { Text("TextEditor".localizedUppercase) .foregroundStyle(.secondary) Spacer() } } } Plain Text encode, decode and sync like a charm through iOS and macOS Use of "FontAttributes" (Bold, Italic, …) works the same But use of "ForegroundColorAttributes" trigger an error : Failed to decode AttributedString: dataCorrupted(Swift.DecodingError.Context(codingPath: [_CodingKey(stringValue: "Index 3", intValue: 3), AttributeKey(stringValue: "SwiftUI.ForegroundColor", intValue: nil), CodableBoxCodingKeys(stringValue: "value", intValue: 1)], debugDescription: "Platform color is not available on this platform", underlyingError: nil)) Is there a way to encode/decode attributedString data platform conditionally ? Or another approach ? Thanks for advices
0
0
162
2w
Is there a way to search in SwitData optional to many relationships?
Done this model: @Model public final class Category: Codable { var nom: String = "" @Relationship(deleteRule: .cascade, inverse: \Property.category) var properties: [Property]? } How to create #predicate to search text in like… let predicate = #Predicate<Category> { category in searchText.isEmpty || category.nom.localizedStandardContains(searchText) || category.properties.contains { $0.nom.localizedStandardContains(searchText) } } without this error: SQLCore dispatchRequest: exception handling request: <NSSQLCountRequestContext: 0x6000038dc620>, to-many key not allowed here with userInfo of (null)
0
0
551
May ’24