Posts

Post not yet marked as solved
0 Replies
218 Views
I've previously used NSKeyedUnarchiver.unarchiveTopLevelObjectWithData to unarchive data that I've previously archived and stored in a data model. I'm now trying to switch from NSKeyedUnarchiver.unarchiveTopLevelObjectWithData to unarchivedObject(ofClass:from:) as NSKeyedUnarchiver.unarchiveTopLevelObjectWithData is deprecated. I've tried an absolute pile of attempts to get this to work and I feel I've just gotten further and further away from working code. Below is my original code to archive and unarchive. Could someone please show me what needs to be done for the conversion to the new method? Thanks. ARCHIVING CODE var selectedAmenities = [String: String]() var archivedAmenities: Data! do { archivedAmenities = try NSKeyedArchiver.archivedData(withRootObject: selectedAmenities, requiringSecureCoding: false) } catch { print("Couldn't archive the Amenities.") } UNARCHIVING CODE var selectedAmenities = [String: String]() do { let unArchivedAmenities = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(campSight.amenities!) selectedAmenities = unArchivedAmenities as! [String: String] } catch { print("Couldn't unarchive the Amenities.") }
Posted Last updated
.