I want to store string every time in array via NSUserDefaults. and i want to retrive that strings(set of string) it in a UITableView cell
.
My code
enum defaultsKeys {
static let keymodel = "firstStringKey"
static let keyVersion = "secondStringKey"
static let keyBodystyle = "thirdStringKey"
static let keyTotalprice = "fourthStringKey"
static let keyDate = "fifthStringKey"
}
override func viewDidLoad() {
super.viewDidLoad()
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setValue(mymodel, forKey: defaultsKeys.keymodel)
defaults.setValue(myversion, forKey: defaultsKeys.keyVersion)
defaults.setValue(mybodystyle, forKey: defaultsKeys.keyBodystyle)
defaults.setValue(mytotalprice, forKey: defaultsKeys.keyTotalprice)
defaults.setValue(mymodel, forKey: defaultsKeys.keyDate)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:selectedcarcell = tableView.dequeueReusableCellWithIdentifier("selectedcarcell") as! selectedcarcell
let defaults = NSUserDefaults.standardUserDefaults()
if let stringmodel = defaults.stringForKey(defaultsKeys.keymodel) {
cell.carname.text = stringmodel
}
if let stringversion = defaults.stringForKey(defaultsKeys.keyVersion) {
cell.carversion.text = stringversion
}
if let stringbodystyle = defaults.stringForKey(defaultsKeys.keyBodystyle) {
cell.carbodystyle.text = stringbodystyle
}
if let stringfinalprice = defaults.stringForKey(defaultsKeys.keyTotalprice) {
cell.finalprice.text = stringfinalprice
}
if let stringdate = defaults.stringForKey(defaultsKeys.keyDate) {
cell.date.text = stringdate
}
return cell
}
I am doing this for string but i want to do this for array so how can I do this
But when second time i insert nother values my previous values are not coming in array. so how can i do this i also want all previous value?