Code:
var contactArray = [nameField.text, addressField.text, phoneField.text]
NSKeyedArchiver.archiveRootObject(contactArray, toFile: dataFilePath!)
//Error on contactArray: Argument type '[String?]' does not conform to expected type 'AnyObject'
Since the contactArray is a non optional value, I can't force unwrap it, what should I do?
You are correct that contactArray is not an optional; it's an array of optionals. You need to unwrap each individual element of the array as you construct it, e.g.:
var contactArray = [nameField.text!, addressField.text!, phoneField.text!]
Also, unless you plan on modifying that array later, you should use let instead of var to make sure it can't be modified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With