Search code examples
iosobjective-cnsuserdefaultsnsindexpath

How to set Default Object at indexPath?


I want to save data to a specific index in my table.

Here's what I want to achieve theoretically:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:cell.label.text forKey:indexPath];

What is the correct way of doing this?


Solution

  • Try this

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:cell.label.text forKey:[indexPath description]];