swift type + class question.

see this first : https://developer.apple.com/documentation/foundation/nskeyedunarchiver/2963379-unarchivedobject


if I were to try to call this function:

@nonobjc static func unarchivedObject(ofClasses classes: [AnyClass], from data: Data) throws -> Any?

what is Swift expecting to see where it says : [AnyClass] ?


currently I have :

NSKeyedUnarchiver.unarchivedObject(ofClasses: [BKControlProps], from: data)

(where BKControlProps is a class type)

... and that's not right.

Accepted Reply

When you want to use class itself as a value (that is what `AnyClass` means), you need to put `.self`.


Please try this:

NSKeyedUnarchiver.unarchivedObject(ofClasses: [BKControlProps.self], from: data)

Replies

When you want to use class itself as a value (that is what `AnyClass` means), you need to put `.self`.


Please try this:

NSKeyedUnarchiver.unarchivedObject(ofClasses: [BKControlProps.self], from: data)

thanks.

unfortunately, this method requires secureCoding support, I was not happy to find that out.

so It's not worth the effort. If I were going to update my coding, I'd use the Swift Coding system, and skip this mess altogether. I just need to cobble together something in a few minutes out of old parts.

unfortunately, this method requires secureCoding support, I was not happy to find that out.

The requirement to support secure coding is a relatively recent addition and you can disable it (via the various initialisers that support a

requiresSecureCoding
parameter). Now whether you should do that is another matter!

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

eskimo,

I have in the last year tried to adopt secure coding. it was an absolute mess. net result is that I found no way to support secure coding without breaking it. As far as I can tell, it is unfinished, and just creates a circular system of errors.

I’m happy to help with that but it’d probably be best to put the specifics in a separate thread.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"