Reputation: 5259
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
Reputation: 21
Easiest solution for saving UIColor to CoreData that worked for me:
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)
}
}
add to didFinishLaunchingWithOptions in AppDelegate:
ColorTransformer.register()
in .xcdatamodel > problematic atribute > Data Model Inspector > Transformer - "ColorTransformer"
Upvotes: 2
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
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.
Upvotes: 56
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
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
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