0

Currently I'm saving bookmarks in NSMutableIndexSet

- (BOOL)saveBookmark
{
if (!bookmarkIndex) {
    bookmarkIndex = [NSMutableIndexSet indexSet];
}
if (currentIndex) {
    [bookmarkIndex addIndex:currentIndex];
    return [bookmarkIndex containsIndex:currentIndex];
}
return NO;
}

But when I exit the app and come back to check on bookmarks, the bookmarks are not showing then.

So thinking of storing bookmarks in NSUserDefaults.

Is it possible to store NSMutableIndexSet in NSUserDefaults or only NSMutableArray can be saved in NSUserDefaults.

Is there is any example of storing NSMutableIndexSet in NSUserDefaults?

Appreciate help.

Thanks

Legoless
  • 10,942
  • 7
  • 48
  • 68
user1120133
  • 3,244
  • 3
  • 48
  • 90

1 Answers1

1

In NSUserDefaults all you can store are property lists. Read more about them here:

https://developer.apple.com/Library/ios/documentation/Cocoa/Conceptual/PropertyLists/AboutPropertyLists/AboutPropertyLists.html#//apple_ref/doc/uid/10000048i-CH3-54303

As you can see, you cannot store a NSIndexSet in a property list, so you will need to use either a NSArray or a NSDictionary. I do not see any reason why cannot you store an array.

See the answer below on how to get indexes into an array:

Community
  • 1
  • 1
Legoless
  • 10,942
  • 7
  • 48
  • 68