How to use NSUserDefaults to store an array of dictionaries

前端 未结 2 721
悲哀的现实
悲哀的现实 2021-01-28 09:21

Trying to store an array of dictionaries with NSUserDefaults.

var theTasks: [[String:Any]] = [[\"num\":1,\"title\":\"example\",\"colour\":\"red\"]]          


        
2条回答
  •  不知归路
    2021-01-28 10:07

    Just call the .setObject() method directly from NSUserDefaults()and it should work fine.

    NSUserDefaults().setObject(theTasks, forKey: "myTasks")

提交回复
热议问题