(Swift) Storing and retrieving Array to NSUserDefaults

前端 未结 7 1003
别跟我提以往
别跟我提以往 2020-11-30 05:43

I am trying to store an array to NSUserDefaults and retrieve the array when needed to populate a UITableView.

Currently I am using:

<
7条回答
  •  佛祖请我去吃肉
    2020-11-30 06:27

    What are you storing in the array?

    If it's objects it won't work, if It's just strings or numbers then it should be fine.

    Next steps you take should be to turn on exception breakpoints and maybe println() everything you can so you can pinpoint the exact whereabouts of the problem.

    As a shot in the dark I would suggest maybe (identity.text!) is coming out as nil

    Also you should probably change it to this

    if let tabledata: NSArray = NSUserDefaults.standardUserDefaults().stringForKey("\(identity.text!)listA"){
    
        myArray = [tabledata!]
    
        tableView.reloadData()
    }
    

    This will make the code not even try to run unless there is a value it can use

提交回复
热议问题