Guest User

Untitled

a guest
May 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. + (void)getIdeasTasksWithPageNo:(int)pageNo completionHandler:(void (^)(NSArray *, NSError *))completionHandler {
  2.  
  3. NSArray *tasks = [self MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"due_date = nil AND user_id = %@", [DBUsers currentUser].id]];
  4. completionHandler(tasks, nil);
  5. }
  6.  
  7. [DBTasks getIdeasTasksWithPageNo:1 completionHandler:^(NSArray *tasks, NSError *error) {
  8. if (!error) {
  9. [self displayTasksWithResults:tasks forPageNo:1];
  10.  
  11. } else {
  12. NSLog(@"Error is %@", error);
  13. }
  14. }];
  15.  
  16. -(void)displayTasksWithResults:(NSArray *)tasks forPageNo:(int)pageNo {
  17. if (!self.tasksArray) {
  18. self.tasksArray = [[NSMutableArray alloc] init];
  19.  
  20. } else {
  21. [self.tasksArray removeAllObjects];
  22. }
  23. [self.tasksArray addObjectsFromArray:tasks];
  24. [self.tableview reloadData];
  25. }
  26.  
  27. (
  28. "Title: Task 01",
  29. "Title: You've gone incognito. Pages you view in incognito tabs won't stick around in your browser's history, cookie store, or search history after you've closed all of your incognito tabs. Any files you download or bookmarks you create will be kept. ",
  30. "Title: Task 06",
  31. "Title: Task 04",
  32. "Title: Hi",
  33. "Title: Task 3",
  34. "Title: Task 4",
  35. "Title: Hi 4",
  36. "Title: hh",
  37. "Title: Task 02",
  38. "Title: Task 05n",
  39. "Title: Task 4",
  40. "Title: Task 5",
  41. "Title: Task 2 updated",
  42. "Title: Here is a task. ",
  43. "Title: Task 03",
  44. "Title: Hi 3",
  45. "Title: Task 2",
  46. "Title: Hi 2",
  47. "Title: Testing task email with Idea Task",
  48. "Title: Task f6",
  49. "Title: 1.117",
  50. "Title: Task f5",
  51. "Title: Task f12",
  52. "Title: Task f4",
  53. "Title: Task f3",
  54. "Title: 111.0.113",
  55. "Title: 111.0.115",
  56. "Title: Pages you view in incognito tabs won't stick around in your browser's history, cookie store, or search history after you've closed all of your incognito tabs. Any files you download or bookmarks you create will be kept.",
  57. "Title: Task f7",
  58. "Title: 1.116",
  59. "Title: 1.118",
  60. "Title: Going incognito doesn't hide your browsing from your employer, your internet service provider, or the websites you visit. ",
  61. "Title: 111.0.111"
  62. )
  63.  
  64. (
  65. "Title: (null)",
  66. "Title: (null)",
  67. "Title: (null)",
  68. "Title: (null)",
  69. "Title: (null)",
  70. "Title: (null)",
  71. "Title: (null)",
  72. "Title: (null)",
  73. "Title: (null)",
  74. "Title: (null)",
  75. "Title: (null)",
  76. "Title: (null)",
  77. "Title: (null)",
  78. "Title: (null)",
  79. "Title: (null)",
  80. "Title: (null)",
  81. "Title: (null)",
  82. "Title: (null)",
  83. "Title: (null)",
  84. "Title: (null)",
  85. "Title: (null)",
  86. "Title: (null)",
  87. "Title: (null)",
  88. "Title: (null)",
  89. "Title: (null)",
  90. "Title: (null)",
  91. "Title: (null)",
  92. "Title: (null)",
  93. "Title: (null)",
  94. "Title: (null)",
  95. "Title: (null)",
  96. "Title: (null)",
  97. "Title: (null)",
  98. "Title: (null)"
  99. )
  100.  
  101. NSManagedObject *copy = [[mainContext objectWithID:[object objectID]];
  102.  
  103. [fetchRequest setResultType:NSDictionaryResultType];
  104. [fetchRequest setPropertiesToFetch:@[@"title", ...]];
  105.  
  106. + (NSManagedObjectContext *) MR_contextForCurrentThread;
  107. {
  108. if ([NSThread isMainThread])
  109. {
  110. return [self MR_defaultContext];
  111. }
  112. else
  113. {
  114. NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
  115. NSManagedObjectContext *threadContext = [threadDict objectForKey:kMagicalRecordManagedObjectContextKey];
  116. if (threadContext == nil)
  117. {
  118. threadContext = [self MR_contextWithParent:[NSManagedObjectContext MR_defaultContext]];
  119. [threadDict setObject:threadContext forKey:kMagicalRecordManagedObjectContextKey];
  120. }
  121. return threadContext;
  122. }
  123. }
  124.  
  125. + (void)backgroundFetchWithPredicate:(NSPredicate *)predicate completion:(void(^)(NSArray *, NSError *))completion {
  126. NSManagedObjectContext *privateContext = [NSManagedObjectContext MR_context];
  127. [privateContext performBlock:^{
  128. NSArray *privateObjects = [self MR_findAllWithPredicate:predicate inContext:privateContext];
  129. NSArray *privateObjectIDs = [privateObjects valueForKey:@"objectID"];
  130. // Return to our main thread
  131. dispatch_async(dispatch_get_main_queue(), ^{
  132. NSPredicate *mainPredicate = [NSPredicate predicateWithFormat:@"self IN %@", privateObjectIDs];
  133. NSArray *finalResults = [self MR_findAllWithPredicate:mainPredicate];
  134. completion(finalResults, nil);
  135. });
  136. }];
  137. }
  138.  
  139. [self backgroundFetchWithPredicate:predicate completion:^(NSArray *results, NSError *error) {
  140. completionHandler(results, error);
  141. }];
  142.  
  143. NSArray *tasks = [[self MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"due_date = nil AND user_id = %@", [DBUsers currentUser].id]] mutableCopy];
  144.  
  145. // NullFieldsCoreDataObject.h
  146. @interface NullFieldsCoreDataObject : NSManagedObject
  147. @property (nonatomic, retain) NSString * nullField;
  148. @property (nonatomic, retain) NSString * anotherOneNullField;
  149. @property (nonatomic, retain) NSNumber * andAnotherOneNullField;
  150. @end
  151.  
  152. // NullFieldsCoreDataObject.m
  153. #import "NullFieldsCoreDataObject.h"
  154.  
  155. @implementation NullFieldsCoreDataObject
  156. // wrong:
  157. //@synthesize nullField, anotherOneNullField, andAnotherOneNullField;
  158. // correctly:
  159. @dynamic nullField, anotherOneNullField, andAnotherOneNullField;
  160. @end
Add Comment
Please, Sign In to add comment