Posts

Post marked as solved
3 Replies
166 Views
Hello together, I hope someone can answer and can give me maybe a little guidance. Is it possible to access and change a child value from a child class in SwiftData? I tried now different ways but couldn't get it to work although I don't get any errors but I am not able to change or set any values. So the code example below is only a simplified example and I know some minor errors but it is about the principle. Can the Father class access somehow the Children class and for example read the childrenName? @Model class Father { var father: String var child: Child? } @Model class Child { var childName: String var child: Children? var father: Father } @Model class Children { var childrenName: String var parent: Child } I don't need direct access from the Father to the Children class - it has to go via the child class. Thanks for any direction or feedback in advance.
Posted
by marc1881.
Last updated
.
Post not yet marked as solved
0 Replies
172 Views
Hey there, I am having a question which hopefully someone can answer. I am developing an App and wanted to store Images in SwiftData with the @External Storage Attribute. I get it to work with a single image and also with an array of images but...saving 1 Image shows a storage space of about 38 bytes but when I store an array of 3 Images the storage in the SQL Database (Blob Type) increases to over 8 Million Bytes? Is this a bug or is this what it is? I am having a direction for a workaround but it would be more convenient if it would work with SwiftData for an array of images same as it does for 1 image. Thanks for any clarification.
Posted
by marc1881.
Last updated
.
Post not yet marked as solved
0 Replies
234 Views
Hello all, I am struggling with a Predicate in SwiftData, not sure if that is not yet supported but maybe I am on the wrong path.. I have a class which contains an Array of Strings (Tags) which I want to search on, so I need to filter this array with a Predicate but I can't get it to work, any suggestions? Here is the code: Class @Model class Tasks { var taskTitle: String = "x" var taskDueDate: Date = Date.now var taskDetails: String = "x" var taskCompleted: Bool = false var taskTags: [String]? = [] var taskAddingDate: Date = Date.now init(taskTitle: String, taskAddedDate: Date, taskDetails: String, taskCompleted: Bool, taskTags:[String]? = nil, taskAddingDate: Date) { self.taskTitle = taskTitle self.taskDueDate = taskAddedDate self.taskDetails = taskDetails self.taskCompleted = taskCompleted self.taskTags = taskTags self.taskAddingDate = taskAddingDate } } Predicate I have so far (it is compiling and it runs without any problems but it is not returning anything) If I leave the searchString empty I get all the tasks, so filtering with the searchString is not woking. init(sortSelection: SortOptionTasks, addTask: Binding<Bool>, completedTask: Binding<Bool>, searchString: String, sortOrder: [SortDescriptor<Tasks>] = []) { self.sortSelection = sortSelection self._addTask = addTask self._completedTask = completedTask _task = Query(filter: #Predicate { task in if searchString.isEmpty { true } else { task.taskTags!.contains { $0 == searchString } == true } } , sort: sortOrder) }
Posted
by marc1881.
Last updated
.