Core Data -existingObjectWithID:error: causes error 133000

The problem is that NSManagedObjectID you pass is temporary. You can check it by calling NSManagedObjectID‘s isTemporaryID method. From docs: Returns a Boolean value that indicates whether the receiver is temporary. Most object IDs return NO. New objects inserted into a managed object context are assigned a temporary ID which is replaced with a permanent … Read more

NSFetchedResultsController: changing predicate not working?

I had almost exactly this problem, until I found the hint in a very recent blog post at iphone incubator NSFetchedResultsController is caching the first results. (You probably have something set at initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName) I’m guessing your code (like mine) is a derivation of the CoreData sample, so assuming it’s @”Root”, before you change the predicate, … Read more

How to fetch only the first record in Core Data?

You can use the setFetchLimit: method on NSFetchRequest to limit the number of records fetched. So if you only want the first record: // Given some existing NSFetchRequest *request and NSManagedObjectContext *context: [request setFetchLimit:1]; NSError *error; NSArray *results = [context executeFetchRequest:request error:&error]; Note that the call to executeFetchRequest:error: will still return an NSArray; you still … Read more

Core Data – How to fetch an entity with max value property

You set the fetchLimit to 1 and sort by personId in descending order. E.g.: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@”Person”]; fetchRequest.fetchLimit = 1; fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@”personId” ascending:NO]]; NSError *error = nil; id person = [managedObjectContext executeFetchRequest:fetchRequest error:&error].firstObject;

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)