Post

Replies

Boosts

Views

Activity

Country from MKReverseGeocoding
As GeoCoder is now deprecated I am struggling to get the country only information from the new MKReverseGeocoding. Maybe someone can guide me or give me direction? Or is this just not possible anymore? let request = MKReverseGeocodingRequest(location: self.lastLocation ?? fallbackLocation) request?.getMapItems { items, error in guard let items = items else { return } self.cityName = items.first?.addressRepresentations?.cityWithContext ?? "" self.countryName = items.first?.addressRepresentations?.regionName ?? "" } I couldn't find anything here, sure you can get the full Address but I need single values to store so the user can search for (example City, Country) In case the structure is always the same, let us say the country is always third part, sure I could split the string but it is not a reliable way to do this, at least for me. Any help would be much appreciated.
1
0
130
Sep ’25
Array<NSNumber> not working for EKRecurringRule in EventKit
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?
1
0
695
Aug ’24
Access an Object and Change Values. up to 2 Class Levels down
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.
3
0
569
Mar ’24
SwiftData - Images & External Storage Attribute
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.
0
0
767
Mar ’24
SwiftData using Predicate on an Array
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) }
1
0
1.3k
Feb ’24