I am having an issue here with the NSNumber Type using with SwiftUI and I am not sure what I am doing wrong here?
@State private var recurringMonthsTest: NSNumber = 1`
let rule = EKRecurrenceRule(
recurrenceWith: recurringOn,
interval: recurringInterval,
daysOfTheWeek: [EKRecurrenceDayOfWeek.init(EKWeekday.monday)],
daysOfTheMonth: [],
monthsOfTheYear: [recurringMonthsTest],
weeksOfTheYear: [],
daysOfTheYear: [],
setPositions: nil,
end: EKRecurrenceEnd.init(occurrenceCount: 8))
}
Here is some basic Code to explain the issue, if you look at the above code it works well, I can also put 2 or more NSNumber single values inside the rule.
But if I start to use the Array as below
let recurringMonthsTest2: Array<NSNumber> = [recurringMonthsTest, recurringMonthsTest1]
let rule = EKRecurrenceRule(
recurrenceWith: recurringOn,
interval: recurringInterval,
daysOfTheWeek: [EKRecurrenceDayOfWeek.init(EKWeekday.monday)],
daysOfTheMonth: [],
monthsOfTheYear: [recurringMonthsTest2],
weeksOfTheYear: [],
daysOfTheYear: [],
setPositions: nil,
end: EKRecurrenceEnd.init(occurrenceCount: 8))
}
It doesn't compile and I get the below error which I don't understand.
`Cannot convert value of type 'Array' to expected element type 'Array.ArrayLiteralElement' (aka 'NSNumber')
As I understand both are of the same value but why they don't compile?
I tried already several versions like [NSNumber] = []
but everything is failing...
What am I doing wrong here, can anyone help?
Post
Replies
Boosts
Views
Activity
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.
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.
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)
}