> On 20 Dec 2017, at 02:07, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> The class must be a kind of AnyClass, so you can’t specify a struct type. 
> Sorry I sent you off in the wrong direction on that.

That’s what I just concluded in an email I started writing.

>> The code I mentioned in my follow-up email seems to work:
>> 
>> let array = decoder.decodeObject(of: [NSArray.self], forKey: kArrayKey) as! 
>> [Int]
> 
> That will compile, but might not work. If you’re doing *secure* decoding then 
> the array of types must contain NSArray *and* the type of the elements in the 
> array. 
> 
> However, if you’re not doing secure decoding (and I don’t think you’re 
> required to, even if secure encoding was used to create the archive), then 
> [NSArray.self] should work.

It compiles and it seems to work. But, as I understand it, NSSecureCoding 
refers to decoding rather than encoding (there aren’t any special encoding 
functions) so I think I am doing secure decoding. I get an exception if I use 
an insecure decoding method, such as:

let array = decoder.decodeObject(forKey: kArrayKey) as! [Int]

What I don’t like about [NSArray.self] is that it’s an artefact of bridging. 
I’m not actually using it in the encoder:

coder.encode(arrayOfInts, forKey: kArrayKey)

Jeremy


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to