nsfetchrequest

executeFetchRequest:error: freezes app

Deadly 提交于 2019-12-04 17:54:16
I don't know what it is but it happens when is fetching elements, well that's what I asume because the app just freezes, I pause the debugging and the debugger stops at a return [__context executeFetchRequest:request error:&error]; Any help about this will be very appreciated. D33pN16h7 Check this post basically you'll need to lock your persistentStoreCordinator because read only calls aren't thread safe. Apple documentation mention this here . Cheers my friend! 来源: https://stackoverflow.com/questions/8002906/executefetchrequesterror-freezes-app

Core Data one-to-many sorting

限于喜欢 提交于 2019-12-04 13:41:42
I have CoreData object "Entity" with @property (nonatomic, retain) NSSet *ImagesSet; Inside ImagesSet are many "ImageEntity" objects. "ImageEntity" have @property (nonatomic, retain) NSNumber * sortKey; How create fetchRequest for "Entity" with imagesSet ordered by sortKey field? NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Entity" inManagedObjectContext:[[DataManager sharedInstance] mainObjectContext]]; [fetchRequest setEntity:entity]; NSString * predicate = some predicate string......; [fetchRequest

Core Data: Fetch via specific property (join relationship)

旧时模样 提交于 2019-12-04 13:30:02
问题 I have an core data model as follows The attributes property of Page is a set of DictionaryEntry , they are values for my Page objects, much like a standard NSDictionary (except all of the keys and values are strings) I have a Page that has a DictionaryEntry with key="title" and value="Home" . How would i form a fetch request to load that specific page? 回答1: You should have a look at the predicate syntax for subqueries. You can not use the usual ANY keyword as this only allows you to match

NSFetchedResultsController multiple entities for UITableView

非 Y 不嫁゛ 提交于 2019-12-04 11:20:46
I have two entities one called Post and one called User. Post<<---->User is the relationship in core data. I am using a NSFetchedResultsController to fetch all Post records in my core data stack and then displaying them in a UITableView. Each cell has an image and that image corresponds to a User.profilePicture. Upon initializing I do not download the profile picture from the server, I only download when it scrolls past that cell (lazy load). Once I download it I save the downloaded image to the corresponding User.profilePicture in the core data stack. Is there a way for

Core data: executeFetchRequest vs performFetch

夙愿已清 提交于 2019-12-04 10:24:50
问题 I want a thorough list regarding comparison between the two. Things I have known: executeFetchRequest : Message sent to MOC Return an array of managed objects Goal: fetch objects from persistent store to MOC With table view: has nothing to do with table view Frequency: often used in a loop, so could be called many many times performFetch : Message sent to FRC After calling it, use fetchedObjects to return an array of managed objects With table view: FRC is specifically for keeping managed

FetchRequest - NSArray element failed to match the Swift Array Element type - Swift 2.0

时光毁灭记忆、已成空白 提交于 2019-12-04 08:50:01
I want to do a NSFetchRequest to display my data into a UICollectionView : import UIKit import CoreData let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate let context: NSManagedObjectContext = appDelegate.managedObjectContext class GarageViewController: UIViewController, UICollectionViewDelegate,UICollectionViewDataSource { @IBOutlet weak var backgroundView: UIImageView! @IBOutlet weak var collectionView: UICollectionView! var voitures: [Voiture] = [Voiture]() override func viewDidLoad() { super.viewDidLoad() collectionView.reloadData() let fetchRequest =

CoreData: Find minimum of calculated property

China☆狼群 提交于 2019-12-04 08:47:14
问题 Say I have a CoreData entity "Point" with two properties x and y (both NSNumber). How would a NSPredicate need to look like to let me find the closest Point to say a,b? for distance = sqrt((x-a) (x-a)+(y-b) (y-b)) While I could define a transient property that calculates a distance to a predefined point I can't see how I could programmatically change that point when launching a fetchrequest. Any help would be greatly appreciated. 回答1: Sorry, but doing arithmetic in an NSPredicate isn't

Check data exist before saving in coredata -Swift

笑着哭i 提交于 2019-12-04 06:10:28
问题 While saving the data am checking whether the data is already exist or not in the entity. Problem here is the above method is not working as expected, when I run the app for very first time it's showing data is already exist. Please check the below code and shed some light. Thanks. func someEntityExists(id: String, entityName: String, type : String, fieldName : String) -> Bool { let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: entityName) if type == "String"{ fetchRequest

avoid duplicate results on Core Data fetch

∥☆過路亽.° 提交于 2019-12-03 20:56:13
I have a subclass of the CoreDataTableViewController (subclass of UITAbleViewController dome by the people on Stanford done to link CoreData and TableViews). On this Class, I want to perform a fecth, sorting by an attribute called "definition" and the code which executes it is the following: - (void)setupFetchedResultsController{ NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:self.entity]; request.propertiesToFetch=[NSArray arrayWithObject:@"definition"]; request.returnsDistinctResults=YES; NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"%K != nil", @

Take action when two separate NSFetchRequests have both completed

≯℡__Kan透↙ 提交于 2019-12-03 20:46:50
I'm using a remote database with Core Data and when I execute the following fetch requests, depending on the internet connection, it can take some time. I'd like to monitor these two requests and, when they are complete -- whether successful or failed -- I'd like to trigger another method. FetchRequest 1: [self.managedObjectContext executeFetchRequest:fetchRequest1 onSuccess:^(NSArray *results) { //Succcess [self.refreshControl endRefreshing]; } onFailure:^(NSError *error) { [self.refreshControl endRefreshing]; }]; FetchRequest 2: [self.managedObjectContext executeFetchRequest:fetchRequest2