nsfetchrequest

How to use binary flags in Core Data?

北城以北 提交于 2019-11-30 00:11:30
I have an int32 attribute in a Core Data database. I use this int as an enum bit field. Is it possible to create a NSPredicate to query items based on the binary value of this int ? Something like @"bitFieldAttribute & 0x0001" ? I'm also wondering if this is possible with a binary typed attribute ? NSPredicate can handle it, but I'm not sure if CoreData will accept it as a valid predicate for execution on a data store. It might have trouble converting the bitwise operator into a SQL query (if you're using a SQLite backing store). You'll just have to try it. The syntax, however, is just what

iOS CoreData NSPredicate to query multiple properties at once

此生再无相见时 提交于 2019-11-29 21:44:06
I am trying to use a UISearchBar to query multiple properties of a NSManagedObject I have a NSManagedObject called Person , every person has a name and socialSecurity property. Right now my code can perform a search (fetch) for one of those properties or the other, but not both at the same time. - (void) performFetch { [NSFetchedResultsController deleteCacheWithName:@"Master"]; // Init a fetch request NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"MainObject" inManagedObjectContext:self.managedObjectContext];

Core Data pattern: how to efficiently update local info with changes from network?

主宰稳场 提交于 2019-11-29 21:08:51
I have some inefficiency in my app that I'd like to understand and fix. My algorithm is: fetch object collection from network for each object: if (corresponding locally stored object not found): -- A create object if (a nested related object locally not found): -- B create a related object I am doing the checking on lines A and B by creating a predicate query with the relevant object's key that's part of my schema. I see that both A (always) and B (if execution branched into that part) generate a SQL select like: 2010-02-05 01:57:51.092 app[393:207] CoreData: sql: SELECT <a bunch of fields>

NSPredicate 'The left hand side for an ALL or ANY operator must be either an NSArray or NSSet'

梦想与她 提交于 2019-11-29 21:06:29
问题 Not totally sure why this isn't working now, i thought it had been working previously. Does anyone see an issue with this FetchRequest construction? - (NSArray *)entriesForDate:(NSDate *)date { NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY addedOn.unique like %@", [T3Utility identifierForDate:date]]; request.predicate = predicate; NSError *error = nil; NSArray *matches = [self.database

fetch core data string and place in a label (Swift4)

为君一笑 提交于 2019-11-29 18:12:05
I am trying to call 2 different core data strings and place them each on separate labels. Right now I am getting the error Cannot invoke initializer for type 'init(_:)' with an argument list of type '([NSManagedObject])'. This error is coming from j1.text = String(itemsName). I added both view controllers for saving and displaying. import UIKit import CoreData class ViewController: UIViewController { @IBOutlet var j1 : UITextField! @IBOutlet var j2 : UITextField! @IBAction func save(){ let appD = UIApplication.shared.delegate as! AppDelegate let context = appD.persistentContainer.viewContext

NSDictionaryResultType expression not taking into account newly inserted objects

跟風遠走 提交于 2019-11-29 10:55:44
I want the maximum value of a field in core data so I have set up the following request: // Create fetch NSFetchRequest *fetch = [[NSFetchRequest alloc] init]; [fetch setEntity:[NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:context]]; [fetch setResultType:NSDictionaryResultType]; // Expression for Max ID NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"myNumbericID"]; NSExpression *minExpression = [NSExpression expressionForFunction:@"max:" arguments:[NSArray arrayWithObject:keyPathExpression]]; NSExpressionDescription *expressionDescription = [

How to use predicates with fetchRequest in Core Data

一世执手 提交于 2019-11-29 07:03:21
I pass a contact Identifier from Contacts tableview controller to another Location tableview controller. So I define a delegate ContactSelectionDelegate and implement method userSelectedContact in Location tableview controller and get contactIdentifierString I am searching the database to find a match for contactIdentifierString and find value for another attribute provider name. This involves searching the whole database. Is there a faster way by assigning a predicate to the context fetchRequest. I thought that would be faster and fewer lines of code. Can someone suggest how to use predicates

iOS CoreData NSPredicate to query multiple properties at once

做~自己de王妃 提交于 2019-11-28 17:33:53
问题 I am trying to use a UISearchBar to query multiple properties of a NSManagedObject I have a NSManagedObject called Person , every person has a name and socialSecurity property. Right now my code can perform a search (fetch) for one of those properties or the other, but not both at the same time. - (void) performFetch { [NSFetchedResultsController deleteCacheWithName:@"Master"]; // Init a fetch request NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity =

Core Data pattern: how to efficiently update local info with changes from network?

戏子无情 提交于 2019-11-28 17:15:24
问题 I have some inefficiency in my app that I'd like to understand and fix. My algorithm is: fetch object collection from network for each object: if (corresponding locally stored object not found): -- A create object if (a nested related object locally not found): -- B create a related object I am doing the checking on lines A and B by creating a predicate query with the relevant object's key that's part of my schema. I see that both A (always) and B (if execution branched into that part)

iOS: natural sort order

依然范特西╮ 提交于 2019-11-28 14:02:13
I have an app for iOS that uses Core Data to save and retrieve data. How would I fetch data sorted by a field of NSString type in natural sort order ? Right now the result is: 100_title 10_title 1_title I need: 1_title 10_title 100_title You can use localizedStandardCompare: as selector in the sort descriptor for the Core Data fetch request, for example NSSortDescriptor *titleSort = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedStandardCompare:)]; [fetchRequest setSortDescriptors:[titleSort]]; Swift 3: let titleSort = NSSortDescriptor(key: "title",