• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Pasteboards and NSSecureCoding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pasteboards and NSSecureCoding


  • Subject: Re: Pasteboards and NSSecureCoding
  • From: Jeremy Hughes <email@hidden>
  • Date: Wed, 20 Dec 2017 01:38:58 +0000

Thanks, Quincey.

> That looks like Swift 3 code. The current version of the function is like
> this:
>
>> @nonobjc func decodeObject(of classes: [AnyClass]?, forKey key: String) ->
>> Any?

@nonobjc means this is Swift-specfic then?

The init function I’m using is marked as @objc:

@objc required init(coder decoder: NSCoder)
{
}

> On 20 Dec 2017, at 01:25, Quincey Morris
> <email@hidden> wrote:
>
> so you’d specify [NSArray.self, <something>.self] for the first parameter.
> (Note, it’s a Swift-specific wrapper function, not just a direct API
> translation.)
>
> You’ll have to figure out what type to use for the Ints. If they were
> actually saved compatibly with Obj-C, the Ints will actually be NSNumbers,
> and you’ll need to say “NSNumber.self”. If the Ints are stored opaquely as
> Ints, I guess it would be Int.self. You should be able to figure out the
> right type by trial and error, I’d say.
>
> (Actually, if the array itself was saved opaquely, then you’ll need something
> like [[Int].self], I guess. This is an area subject to automatic bridging, so
> what you get depends on the exact code used to encode the archive.)

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

gives an error:

Cannot invoke 'decodeObject' with an argument list of type '(of: [[Int].Type],
forKey: String)’

The code I mentioned in my follow-up email seems to work:

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

Presumably as! would throw an exception if it’s not an array of Ints, so that
does get checked (and using as? with a failable initializer would presumably be
better).

If I replace [NSArray.self] with [Array.self] I get an error:

Ambiguous reference to member 'decodeObject(of:forKey:)’

I’ve also tried [Array<Int>.self], which gives a different error:

Cannot invoke 'decodeObject' with an argument list of type '(of:
[Array<Int>.Type], forKey: String)’

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

  • Follow-Ups:
    • Re: Pasteboards and NSSecureCoding
      • From: Quincey Morris <email@hidden>
References: 
 >Pasteboards and NSSecureCoding (From: Jeremy Hughes <email@hidden>)
 >Re: Pasteboards and NSSecureCoding (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Pasteboards and NSSecureCoding
  • Next by Date: Re: Pasteboards and NSSecureCoding
  • Previous by thread: Re: Pasteboards and NSSecureCoding
  • Next by thread: Re: Pasteboards and NSSecureCoding
  • Index(es):
    • Date
    • Thread