zombie
zombie

Reputation: 5259

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

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?

Upvotes: 42

Views: 28754

Answers (6)

dvd.trsnk
dvd.trsnk

Reputation: 21

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)
        }
    }
    
  2. add to didFinishLaunchingWithOptions in AppDelegate:

    ColorTransformer.register()

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

Upvotes: 2

anoop4real
anoop4real

Reputation: 7708

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

Upvotes: 0

Andrey Chernoprudov
Andrey Chernoprudov

Reputation: 1359

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

Upvotes: 56

Leszek Szary
Leszek Szary

Reputation: 10336

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.

Upvotes: 0

Lutz
Lutz

Reputation: 1984

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.

Upvotes: 22

spnkr
spnkr

Reputation: 1362

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

Upvotes: 31

Related Questions