nssecurecoding

NSKeyedUnarchiver.unarchiveTopLevelObjectWithData return nil

房东的猫 提交于 2021-02-11 15:14:16
问题 I want to save an array of objects into UserDefaults and load it back. When trying to unarchive the data it always returns nil.. any idea? This is my object: class DbInsideLevel: NSObject, NSSecureCoding { static var supportsSecureCoding: Bool { return true } let idNum: Int! var topicId: Int = 0 var tryCount: Int = 0 var score: Int = 0 var isOpen: Bool = false var lastPlayedDate: Date? init(idNum: Int, topicId: Int, tryCount: Int = 0, score: Int = 0, open: Bool, lastPlayedDate: Date?) { self

Crash when adopting NSSecureUnarchiveFromDataTransformer for a Transformable property

喜你入骨 提交于 2021-02-07 06:47:15
问题 In iOS 12 Apple introduced NSSecureUnarchiveFromDataTransformerName for use on CoreData model entities' Transformable properties. I used to keep the Transformer Name field empty, which implicitly used NSKeyedUnarchiveFromDataTransformerName . This transformer is now deprecated, and keeping the field empty in the future will mean NSSecureUnarchiveFromDataTransformerName instead. In iOS 13, if that field is empty, you now get a runtime warning telling you the aforementioned. I couldn't find any

NSSecureCoding trouble with collections of custom class

懵懂的女人 提交于 2019-12-30 03:20:07
问题 I am having trouble with adopting NSSecureCoding. I encode an array containing objects of my custom class, which adopts NSSecureCoding properly. When I decode it, passing the class NSArray (which is the class of the object I encoded), it throws an exception. However, when do the exact same thing with an array of strings, it works fine. I fail to see what is the difference between my class and NSString. #import <Foundation/Foundation.h> @interface Foo : NSObject <NSSecureCoding> @end

Strange behavoir when decoding an NSArray via NSSecureCoding

元气小坏坏 提交于 2019-12-21 12:05:20
问题 i spent all afternoon banging my head against the wall trying to figure out why decoding of this class was failing. the class has a property that is an NSArray of Foo objects. Foo conforms to NSSecureCoding, and i have successfully encoded and decoded that class by itself. i was getting an error in initWithCoder: that said failed to decode class Foo. through some experimentation, i discovered that i needed to add [Foo class] to initWithCoder: in order for it to work. maybe this will help

When to use NSSecureCoding

眉间皱痕 提交于 2019-12-09 07:41:24
问题 I'm learning about the NSSecureCoding protocol introduced by Apple in iOS 6. From my understanding so far, it should be used whenever a class encodes/decodes instances of itself, in order to prevent substitution attacks. I'm wondering whether it would be appropriate to use it in other cases. Specifically if a class conforms to NSCoding by encoding/decoding its instance variables, as opposed to the whole instance of itself, would it still be advisable to implement NSSecureCoding ? EDIT Suppose

How to use NSSecureCoding with id objects

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 01:07:55
问题 I'm creating a linked list and using containers to group the object, next, and previous properties. Like Foundation collections, I'd like it to implement NSSecureCoding . Here's the declaration: @interface ListContainer : NSObject <NSCopying, NSSecureCoding> @property (readonly, nonatomic) id object; @property (nonatomic) ListContainer * next; @property (nonatomic) ListContainer * previous; @end When implementing the - initWithCoder: method it hit me that I don't know what class to use for

How to use NSSecureCoding with id objects

本小妞迷上赌 提交于 2019-12-04 05:11:06
I'm creating a linked list and using containers to group the object, next, and previous properties. Like Foundation collections, I'd like it to implement NSSecureCoding . Here's the declaration: @interface ListContainer : NSObject <NSCopying, NSSecureCoding> @property (readonly, nonatomic) id object; @property (nonatomic) ListContainer * next; @property (nonatomic) ListContainer * previous; @end When implementing the - initWithCoder: method it hit me that I don't know what class to use for the object: - (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; if (self) { _object

Strange behavoir when decoding an NSArray via NSSecureCoding

允我心安 提交于 2019-12-04 04:42:14
i spent all afternoon banging my head against the wall trying to figure out why decoding of this class was failing. the class has a property that is an NSArray of Foo objects. Foo conforms to NSSecureCoding, and i have successfully encoded and decoded that class by itself. i was getting an error in initWithCoder: that said failed to decode class Foo. through some experimentation, i discovered that i needed to add [Foo class] to initWithCoder: in order for it to work. maybe this will help someone else who's having the same problem. my question is, why is this necessary? i found no suggestion

When to use NSSecureCoding

☆樱花仙子☆ 提交于 2019-12-03 09:34:30
I'm learning about the NSSecureCoding protocol introduced by Apple in iOS 6. From my understanding so far, it should be used whenever a class encodes/decodes instances of itself, in order to prevent substitution attacks. I'm wondering whether it would be appropriate to use it in other cases. Specifically if a class conforms to NSCoding by encoding/decoding its instance variables, as opposed to the whole instance of itself, would it still be advisable to implement NSSecureCoding ? EDIT Suppose I have a class that is implementing NSCoding like follows - (void)encodeWithCoder:(NSCoder *)encoder {