Guest User

Untitled

a guest
Jan 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. + (NSMutableArray *)bookmarkCollection {
  2.  
  3. NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
  4.  
  5. if (!bookmarkCollection) {
  6.  
  7. bookmarkCollection = [[NSMutableArray alloc] init];
  8. }
  9.  
  10. return bookmarkCollection;
  11. }
  12.  
  13. + (void)deleteBookmark: (NSIndexPath *)indexPath {
  14.  
  15. NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
  16.  
  17. [bookmarkCollection removeObjectAtIndex: indexPath.row];
  18.  
  19. [[NSUserDefaults standardUserDefaults] setObject:bookmarkCollection forKey: @"bookmarks"];
  20.  
  21. [[NSUserDefaults standardUserDefaults] synchronize];
  22.  
  23. }
  24. + (void)uploadBookmark:(NSDictionary *)singleBookmark {
  25.  
  26. NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
  27.  
  28.  
  29. if (!bookmarkCollection) {
  30.  
  31. bookmarkCollection = [[NSMutableArray alloc] init];
  32. }
  33.  
  34. NSMutableDictionary *bookmark1 = [[NSMutableDictionary alloc] initWithDictionary: singleBookmark];
  35.  
  36. NSMutableDictionary *bookmark2 = [[NSMutableDictionary alloc] initWithDictionary: singleBookmark];
  37.  
  38.  
  39. NSNumber *number1 = [[NSNumber alloc] initWithInt: 1];
  40. NSNumber *number2 = [[NSNumber alloc] initWithInt: 2];
  41.  
  42. [bookmark1 setObject:number1 forKey: @"bookmarkTag"];
  43. [bookmark2 setObject:number2 forKey: @"bookmarkTag"];
  44.  
  45. [bookmarkCollection addObject: bookmark1];
  46. [bookmarkCollection addObject: bookmark2];
  47.  
  48. [[NSUserDefaults standardUserDefaults] setObject:bookmarkCollection forKey: @"bookmarks"];
  49.  
  50. [[NSUserDefaults standardUserDefaults] synchronize];
  51.  
  52. }
  53.  
  54. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  55.  
  56.  
  57. if (editingStyle == UITableViewCellEditingStyleDelete) {
  58.  
  59. [BookmarkHandler deleteBookmark: indexPath];
  60.  
  61. [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  62. }
  63. }
  64.  
  65. [bookmarkCollection removeObjectAtIndex: indexPath.row];
  66.  
  67. NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
  68.  
  69. NSMutableArray *bookmarkCollection = [[[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"] mutableCopy];
  70.  
  71. if (indexPath.row>=0 && indexPath.row<bookmarkCollection.count) {
  72. [bookmarkCollection removeObjectAtIndex: indexPath.row];
  73. } else {
  74. NSLog(@"indexPath.row is out of boundry of bookmarkCellection size: %d", bookmarkCollection.count);
  75. }
Add Comment
Please, Sign In to add comment