Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

objective c - NSSecureCoding VS saving id

i am on objective-c, macOS.

I am currently rewriting an application to support NSSecureCoding Protocol. In some classes i have some properties like this

@property id objectValue;

These objects can be of very dynamic kind (NSString, custom object ...) On loading i did this before:

_objectValue = [coder decodeObjectForKey:@"objectValue"];

With NSSecureCoding i need to specify the class which i cannot do with id obviously. So here are my questions:

  1. Is it OK to pass a superclass like NSObject even if it's basically an NSString?

    _objectValue = [coder decodeObjectOfClass:[NSObject class] forKey:@"objectValue"];
    

    But... doesn't this counteract the idea of NSSecureCoding?

  2. Is there another (better) approach?

Edit: Just seen that this is possible with multiple classes decodeObjectOfClasses:forKey: - would the correct approach be to list all classes possible?


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

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...