Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

ios - Transformable and NSKeyedUnarchiveFromData

I'm trying to save a Measurement to a Core Data transformable property. Basically, what's in this answer, only a different unit: How to Save a Generic Measurement<Unit> in Core Data?

Everything works, however I'm getting this message in the log: [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release

I'm not sure how to fix this. Or what exactly it means. This is my first time working with a transformable Core Data property.

Thanks


Edit:

I made a new class:

import Foundation

@objc(UnitTemperatureValueTransformer)
final class UnitTemperatureValueTransformer: NSSecureUnarchiveFromDataTransformer {
    static let name = NSValueTransformerName(rawValue: String(describing: UnitTemperatureValueTransformer.self))
    override static var allowedTopLevelClasses: [AnyClass] {
        return [UnitTemperature.self]
    }
    
    public static func register() {
        let transformer = UnitTemperatureValueTransformer()
        ValueTransformer.setValueTransformer(transformer, forName: name)
    }
}

And then I set the transformer value for the Core Data object to: UnitTemperatureValueTransformer.

Is that all that needs to be done?

question from:https://stackoverflow.com/questions/65545591/transformable-and-nskeyedunarchivefromdata

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This warning appears because apple will remove it in future release because it's not secure by default. Here is thread on Apple forum. You should use NSSecureUnarchiveFromData instead of that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...