2

i have a small problem with my code. When I load data from my CoreData I get warnings in my consol but I don´t know why. I´m not a professional programmer and also google couldn´t really help me so now I´m here.

I load my data like this:

let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

var data: [DataToLoad] = []

override func viewDidLoad(){
do{
    data = try context.fetch(DataToLoad.fetchRequest())
}catch{
    print("error")
}}

But when I load it like that the console says...

"2020-09-05 20:32:04.884728+0200 Test-Application[3850:348569] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release"

...after I start the App.

So I mean everything is working fine, but where is my error that this massage appears. I hope you can help me.

Sorry for my bad english I hope you can understand everything.

Have a nice day and thank you all.

1 Answers1

3

The app is still working because it's a warning and not an error but it's good to not ignore warnings.

In your case, the warning occurs because NSKeyedUnarchiveFromData is deprecated. This means it's outdated and will be replaced in the future and the app might then stop working.

Kaira Diagne explains:

With iOS 12 Apple has started adopting NSSecureCoding across the entire platform. For Core Data this means that the default ValueTransformer, which uses NSCoding to transform a custom data type into a format that can be stored in the persistent store, at some point will change as well.

In your case NSSecureUnarchiveFromData instead of NSKeyedUnarchiveFromData in Core Data.

This means that the first thing we need to do is make sure that the data type of every transformable property in our data model conforms to secure coding.

(Link: NSSecureCoding and transformable properties in Core Data, 2020)

For your app to also work in the future you will have to dig somewhat deeper into the code and see where you are using the deprecated methods and classes and replace them.

Elly
  • 49
  • 1
  • 1
  • 7