nsuserdefaults - How to unarchive data in swift 3? -
i have app save array of cncontact
userdefaults
such:
var contactsarray = [cncontact]() let defaults = userdefaults() func (contact: cncontact){ contactsarray.append(contact) let contactarrayarchive = nskeyedarchiver.archiveddata(withrootobject: contactarray) //archive data defaults.set(contactarrayarchive, forkey: "contactarray") defaults.synchronize() }
this archives data allow saved defaults
. issue how can convert data array of cncontact
in viewdidload
. have seen many answers online suggest use nskeyedarchiver.unarchiveobjectwithdata
typing xcode, swift 3, says .unarchiveobjectwithdata
not member of nskeyedarchiver
. keep looking stuff how in swift 3 have been unsuccessful. how can unarchive value?
you can use
nskeyedunarchiver.unarchiveobject(with: data)
you have used nskeyedarchiver . cannot use unarchive object.
Comments
Post a Comment