Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- + (NSMutableArray *)bookmarkCollection {
- NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
- if (!bookmarkCollection) {
- bookmarkCollection = [[NSMutableArray alloc] init];
- }
- return bookmarkCollection;
- }
- + (void)deleteBookmark: (NSIndexPath *)indexPath {
- NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
- [bookmarkCollection removeObjectAtIndex: indexPath.row];
- [[NSUserDefaults standardUserDefaults] setObject:bookmarkCollection forKey: @"bookmarks"];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- + (void)uploadBookmark:(NSDictionary *)singleBookmark {
- NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
- if (!bookmarkCollection) {
- bookmarkCollection = [[NSMutableArray alloc] init];
- }
- NSMutableDictionary *bookmark1 = [[NSMutableDictionary alloc] initWithDictionary: singleBookmark];
- NSMutableDictionary *bookmark2 = [[NSMutableDictionary alloc] initWithDictionary: singleBookmark];
- NSNumber *number1 = [[NSNumber alloc] initWithInt: 1];
- NSNumber *number2 = [[NSNumber alloc] initWithInt: 2];
- [bookmark1 setObject:number1 forKey: @"bookmarkTag"];
- [bookmark2 setObject:number2 forKey: @"bookmarkTag"];
- [bookmarkCollection addObject: bookmark1];
- [bookmarkCollection addObject: bookmark2];
- [[NSUserDefaults standardUserDefaults] setObject:bookmarkCollection forKey: @"bookmarks"];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- [BookmarkHandler deleteBookmark: indexPath];
- [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationLeft];
- }
- }
- [bookmarkCollection removeObjectAtIndex: indexPath.row];
- NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
- NSMutableArray *bookmarkCollection = [[[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"] mutableCopy];
- if (indexPath.row>=0 && indexPath.row<bookmarkCollection.count) {
- [bookmarkCollection removeObjectAtIndex: indexPath.row];
- } else {
- NSLog(@"indexPath.row is out of boundry of bookmarkCellection size: %d", bookmarkCollection.count);
- }
Add Comment
Please, Sign In to add comment