'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
Asked Answered
S

6

40

I'm receiving a message in the log saying

'bundleNamePlaceholder'[8424:100146] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release

The message is not clear to me but I'm assuming that it might be something related to a CoreData object or maybe its content

Is there a way to catch what's throwing this message or what might cause it?

Selfimmolation answered 26/6, 2020 at 7:28 Comment(0)
P
28

apple is removing NSKeyedUnarchiveFromData at some point because it's not secure by default. if you're storing a transformable value using NSKeyedUnarchiveFromData in coredata, it will then become unreadable.

https://www.kairadiagne.com/2020/01/13/nssecurecoding-and-transformable-properties-in-core-data.html

and https://developer.apple.com/forums/thread/107533

Pulido answered 1/7, 2020 at 6:35 Comment(0)
H
47

In my case the problem was in using Transformable type in CoreData for saving array of strings. By default CoreData uses NSKeyedUnarchiver instead of NSSecureUnarchiveFromData transformer. So changing the transformer solved this problem.

enter image description here

Hibernal answered 22/4, 2021 at 5:58 Comment(0)
P
28

apple is removing NSKeyedUnarchiveFromData at some point because it's not secure by default. if you're storing a transformable value using NSKeyedUnarchiveFromData in coredata, it will then become unreadable.

https://www.kairadiagne.com/2020/01/13/nssecurecoding-and-transformable-properties-in-core-data.html

and https://developer.apple.com/forums/thread/107533

Pulido answered 1/7, 2020 at 6:35 Comment(0)
P
18

To find out what is causing these log messages, try adding symbolic break points for

+[NSKeyedUnarchiver unarchiveObjectWithData:],

+[NSKeyedUnarchiver unarchiveTopLevelObjectWithData:error:], and

+[NSKeyedUnarchiver unarchiveObjectWithFile:]

This helped me finding the culprit.

Primavera answered 9/2, 2021 at 9:11 Comment(4)
In my case problem was because I forgotten to set data type and value transformer for transformable field in the xcdatamodel.Reinold
@Reinold , thanks, by "data type" do you mean the "Custom Class" field ???Intemperate
@Intemperate Yes, I mean the "Custom Class" field.Reinold
It helps in identifying the issue with Xcode 14.2Reich
I
0

Usually this is related to Core Data Transformable attributes however in my case this was also caused by an external library which was using NSValueTransformer.valueTransformerNames to iterate over all value transformer classes available in runtime. This was also causing the same errors in logs and symbolic breakpoints given in other answer here did not catch them. So if you cannot find a reason why you have this logs you might also want to search for NSValueTransformer in your code and check if there isn't a similar problem somewhere.

Interstratify answered 16/12, 2021 at 7:4 Comment(0)
L
0

For me the issue was from GoogleAnalytics framework, thanks to @Lutz I could figure it out. For those facing issue from GA please use the updated sdk, this issue seem to be resolved GA SDK

Lucerne answered 28/12, 2021 at 17:56 Comment(0)
H
0

Easiest solution for saving UIColor to CoreData that worked for me:

  1. Create class in new file:

    import Foundation import UIKit

class ColorTransformer: NSSecureUnarchiveFromDataTransformer { static let name = NSValueTransformerName(rawValue: "ColorTransformer")

override static var allowedTopLevelClasses: [AnyClass] {
    return [UIColor.self]
}

public static func register() {
    let transformer = ColorTransformer()
    ValueTransformer.setValueTransformer(transformer, forName: name)
}

static func registerTransformer() {
    let transformer = ColorTransformer()
    ValueTransformer.setValueTransformer(transformer, forName: name)
}

}

  1. add to didFinishLaunchingWithOptions in AppDelegate:

    ColorTransformer.register()

  2. in .xcdatamodel > problematic atribute > Data Model Inspector > Transformer - "ColorTransformer"

Helbon answered 20/3, 2023 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.