Re: Pasteboards and NSSecureCoding
Re: Pasteboards and NSSecureCoding
- Subject: Re: Pasteboards and NSSecureCoding
- From: Jeremy Hughes <email@hidden>
- Date: Wed, 20 Dec 2017 01:25:00 +0000
It seems that I can write:
let array = decoder.decodeObject(of: [NSArray.self], forKey: kArrayKey) as!
[Int]
But shouldn't I be able to specify that this is an array of Ints, and not just
an array of anything?
I should probably avoid force unwrapping - this ought to be a failable
initializer, right?
Jeremy
--
> On 20 Dec 2017, at 01:09, Jeremy Hughes <email@hidden> wrote:
>
> The release notes for 10.13 say:
>
> If your application is linked on macOS 10.13 SDK or later, classes that
> return NSPasteboardReadingAsKeyedArchive from
> readingOptionsForType:pasteboard: must support secure coding, and will be
> decoded with a coder that requires secure coding.
>
> So I’m updating some of my classes to support NSSecureCoding, and I’m having
> trouble figuring out how I should decode an array of Ints.
>
> Previously, I had:
>
> let array = decoder.decodeObject(forKey: kArrayKey) as! [Int]
>
> I think that I need to replace that with something like:
>
> let array = decoder.decodeObject(of: allowedClasses, forKey: kArrayKey) as!
> [Int]
>
> but I can’t work out how to define allowedClasses.
>
> In a previous discussion, Quincey Morris wrote:
>
>> The solution is to fall back to an explicit NSSet object:
>>
>> let classes = NSSet (objects: NSArray.self, MyElementClass.self)
>> let myArray = coder.decodeObjectOfClasses (classes, forKey: “myArray”)
>
> So I’ve tried:
>
> let allowedClasses = NSSet(objects: NSArray.self, Int.self)
>
> But I get an error: Cannot invoke 'decodeObject' with an argument list of
> type '(of: NSSet, forKey: String)’
>
> I also think there should be a way of doing this that uses Array and Set
> rather than NSArray and NSSet
>
> Jeremy
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden