Tag: nsfetchrequest

iOS CoreData NSPredicate一次查询多个属性

我想使用UISearchBar查询NSManagedObject多个属性我有一个名为Person的NSManagedObject ,每个人都有一个name和socialSecurity属性。 现在我的代码可以对这些属性或其他属性执行search(提取),但不能同时执行这两个属性。 – (void) performFetch { [NSFetchedResultsController deleteCacheWithName:@"Master"]; // Init a fetch request NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"MainObject" inManagedObjectContext:self.managedObjectContext]; [fetchRequest setEntity:entity]; // Apply an ascending sort for the color items //NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Term" ascending:YES selector:nil]; NSSortDescriptor *sortDescriptor; sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"fullName" ascending:YES selector:@selector(caseInsensitiveCompare:)]; NSArray […]

iOS:自然sorting顺序

我有一个使用Core Data来保存和检索数据的iOS应用程序。 我如何获取按自然sorting顺序sorting的NSStringtypes的字段的数据? 现在结果是: 100_title 10_title 1_title 我需要: 1_title 10_title 100_title

从包含id的string形成NSPredicate

我有这个问题,我不知道如何写这个谓词。 我有一个名为联系人的实体,它有一个string属性“页”,让我们说 contact.pages = @"1,5,11,15,17"; 我的数据库中有很多联系人,而且我只想获取包含特定ID的这些联系人。 假设我只想获取这些联系人,哪些页面包含id @“1”。 我可以想到这样的事情, NSPredicate* predicate = [NSPredicate predicateWithFormat:@"self.pages CONTAINS %@", _pageId]; 但我的问题是,这也会得到联系,例如有页= @“11,15”。 那么有关如何实现这一目标的任何想法? 任何build议,我将不胜感激,提前致谢!

在实体中提取选定的属性

我有一个具有多个属性的核心数据实体,我想要一个属性中的所有对象的列表。 我的代码如下所示: let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate let context:NSManagedObjectContext = appDel.managedObjectContext! let sortDesc = NSSortDescriptor(key: "username", ascending: true) let fetchReq = NSFetchRequest(entityName: "Identities") fetchReq.sortDescriptors = [sortDesc] fetchReq.valueForKey("username") let en = NSEntityDescription.entityForName("Identities", inManagedObjectContext: context) userList = context.executeFetchRequest(fetchReq, error: nil) as [Usernames] 但是这给了我一个NSException-错误,我不知道为什么,或者我该怎么做。 我读过NSFetchRequest类的描述,但没有多less意义。 任何build议,将不胜感激。 编辑:从Bluehound提示后,我改变了我的代码: var userList = [Model]() @IBAction func printUsers(sender: AnyObject) { let […]

核心数据,当NSFetchRequest返回NSDictionaryResultType时如何获取NSManagedObject的ObjectId?

我有一个NSFetchRequest返回NSDictionaryResultType的对象的属性。 是否有可能在这个字典中获得对象的ObjectId? 否则,我将需要使用NSManagedObjectResultType的返回types来运行查询,这对于大量返回的项目来说要慢得多。

CoreData获得不同的属性值

我试图将我的NSFetchRequest设置为核心数据来检索实体中特定属性的唯一值。 即 具有以下信息的实体: name | rate | factor | _______|______|________| John | 3.2 | 4 | Betty | 5.5 | 7 | Betty | 2.1 | 2 | Betty | 3.1 | 2 | Edward | 4.5 | 5 | John | 2.3 | 4 | 我将如何设置请求返回一个数组只是:约翰,贝蒂,爱德华?