user1960169
user1960169

Reputation: 3653

Retrieving bool array from NSUserdefaults in swift

I have defined an array like this in my iOS app

var array=[Bool]()

and assigning some bool values to this.After that I am storing this array in my user defaults in this way.

userDefaults.setObject(dm.array, forKey: "array")

Now I want to retrievw this array. So I did like this

dm.array=userDefaults.arrayForKey("array") as! Array

But here im getting an error

Down cast from '[AnyObject]?' to 'Array' only unwraps optional; did you mean to use '!'?

Upvotes: 1

Views: 304

Answers (1)

Yury
Yury

Reputation: 6114

array = userDefaults.objectForKey("array") as? [Bool] ?? [Bool]()

Upvotes: 2

Related Questions