user1120133
user1120133

Reputation: 3234

How to store NSMutableIndexSet in NSUserDefaults?

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

Upvotes: 0

Views: 367

Answers (1)

Legoless
Legoless

Reputation: 11112

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:

Upvotes: 1

Related Questions