-1

I have a bunch of local HTML files and I want to create bookmark functionality in the app. When the user presses the bookmark button, it saves the data in the core data. How to do That?

Neeku
  • 3,646
  • 8
  • 33
  • 43

1 Answers1

1

Bookmark functionality usually consists just of saving a link to existing data. Why do you need Core Data to save that? It would make sense if you had MANY bookmarks. This seems like bit overkill to me at this point. You can however use MagicalRecord (https://github.com/magicalpanda/MagicalRecord) do to the heavy lifting with CoreData.

 // create a bookmark record, you can also add title, image, timestamp, etc...
 NSDictionary *bookmarkRecord = @{"url":"http://www.igraczech.com"};

 // prepare dictionary for all the bookmark records you want to save
 NSMutableDictionary *records = [NSMutableDictionary new];
 [records addObject:bookmarkRecord forKey:@"Bookmark title"];

 // this saves the 'records' dictionary (immutable by default), size limit is about a megabyte or two
 [[NSUserDefaults standardUserDefaults] setObject:records forKey:@"bookmarks"];
 [[NSUserDefaults standardUserDefaults] synchronize];

 // this loads bookmarks into mutable dictionary so you can add/edit/remove/save another one safely
 id savedBookmarks = [[NSUserDefaults standardUserDefaults] objectForKey:@"bookmarks"];

 // here the bookmarks are stored, you should use ivar/property instead of this example
 NSMutableDictionary *bookmarks = [NSMutableDictionary new];

 if (savedBookmarks)
 {
     bookmarks = [bookmarks addContentsFromDictionary:savedBookmarks];
 }
igraczech
  • 2,408
  • 3
  • 25
  • 30