Encoding set of structs in Swift

69 Views Asked by At

I have old code:

let output=NSKeyedUnarchiver.unarchiveObject(withFile: path) as? Set<Cloud>

where Cloud is a struct. And I get warning:

'unarchiveObject(withFile:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead

Yet when I try to use that code I get an error saying:

 Static method 'unarchivedObject(ofClass:from:)' requires that 'Set<Cloud>' conform to 'NSCoding' 

and

 Static method 'unarchivedObject(ofClass:from:)' requires that 'Set<Cloud>' inherit from 'NSObject'

Yet if I try to add those protocols to the struct it answers:

  Non-class type 'Cloud' cannot conform to class protocol 'NSCoding'

what is quite logical as it is a struct. Which code should I use to encode a set of structs?

0

There are 0 best solutions below