I am writing an update to a small app whereby JSON data is taken from a web address, decoded and then loaded into a struct for use.
I also want the to then copy the newly retreived data into core data for use if the app should be offline and connot reach the server.
All is working fine except when it comes to attempting to save the retreived data into core data. I keep getting the slightly vague error
'The operation couldn’t be completed. (Foundation._GenericObjCError error 0.)'
I cant seem to find much good info on this error and what causes it. The print line to check the data is what I'd expect is showing the expected output. Any ideas on causes and how to reslove would be appreciated. I'm fairly new to core data so I'm a bit stuck.
The code I am using to extract each entry and try to save it is as below:
for count in rates {
let newExchange = CURRENCIES(context: viewContext)
newExchange.core_ID = UUID()
newExchange.core_Code = count.CODE
newExchange.core_Rate = count.RATE
newExchange.core_Time = count.TIME
newExchange.core_Flag = count.FLAG
newExchange.core_Country = count.COUNTRY
newExchange.core_Currency_Name = count.CURRENCY_NAME
do {
try viewContext.save()
print("Order saved.") } catch {
print(error.localizedDescription)
print(newExchange.core_ID,count.CODE,count.RATE,count.TIME,count.FLAG,count.COUNTRY,count.CURRENCY_NAME)
}
}