nspredicate

Can I apply multiple predicates to an NSFetchRequest? Would it be better to manually parse my results?

邮差的信 提交于 2019-12-02 17:29:34
Ok I have a basic iPad app that asks for 5 search/filter criteria from the user. Based on this data, I need to go to my core data db, and pull out any managed objects that fit that criteria. It seems like I need to apply more than one predicate to the same request, is that possible? Or could I just write a really long fancy predicate? With multiple requirements? How should I approach that? Would it be a good idea to just grab all the entities through the fetch request, and then loop through each array and grab any objects that I find that fit my search criteria? Please advise! Rog Yes it's

Core Data, try to use NSPredicate to filter a toMany relationship set but get the “to-many key not allowed here” error

余生长醉 提交于 2019-12-02 16:26:33
Here is the model I have: http://www.girardet.ch/model.png My goal is to retrieve all the Quotes with these criterias: belong to a specific theme : the name_en attribute of Themes order by relevancy filtered by Authors (with the alias attribute of Authors) Here is my code: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"ThemeEntries" inManagedObjectContext:_context]; [fetchRequest setEntity:entity]; NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"relevancy" ascending:NO]; NSArray

NSPredicate for time interval

你说的曾经没有我的故事 提交于 2019-12-02 12:22:14
I have one table with 4 fields startdate ,enddate, starttime and endtime. I need to set predicate something like if startdate<= currentdate and currentdate <= enddate if starttime <= currenttime and endtime <= endtime else starttime <= currenttime and currenttime<= 23.00 or 0.00 <= currentime and currentime <= endtime How i set predicate for this type of condition.Current date and current time is the my system time in gmt. You can use NSCompoundPredicate Create NSMutableArray to hold your predicates with their conditions NSMutableArray *conditions = [NSMutableArray array]; Build your

Swift coreData - format date and use it in predicate

雨燕双飞 提交于 2019-12-02 11:58:46
问题 H. I have an entity called Agendadate and one called AgendaEvent. AgendaEvent has a many to many relation with AgendaDate (agendaDates). in my AgendaDate i have an object dates (of type Date). I'm using a predicate like so: fetchRequest.predicate = NSPredicate(format: "ANY agendaDates.dates == %@", date as CVarArg) I'm trying to format dates to have this: "dd MM yyyy" instead of "yyyy MM dd hh:mm:ss" I need to compare in the predicate two dates but without the time? is it possible? UPDATE----

NSPredicate for to-many relationship, where a relationship (NSSet) must contain Entities defined in an NSArray

好久不见. 提交于 2019-12-02 10:12:43
问题 Given the following Core Data Model: -> : to-one releationship ->>: to-many relationship Entity A ->> Entity B Entity B -> A // each B belongs to exactly one A Entity B ->> B // a B can be related to other B's So in class A : @property (nonatomic, retain) NSSet *Bs; In class B : @property (nonatomic, retain) A *A; @property (nonatomic, retain) NSSet *Bs; Assume I have an NSArray *myArray containing (Bj, Bk) . What I want is to fetch all B 's which belong to Ax and are related to Bj and Bk :

Check data exist before saving in coredata -Swift

核能气质少年 提交于 2019-12-02 09:26:15
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.predicate = NSPredicate(format: "\(fieldName) == %@", id) }else{ fetchRequest.predicate = NSPredicate(format:

NSPredicate with a !=?

北城以北 提交于 2019-12-02 09:20:56
I have Core Data Entities Person and Boundary. They have a many-to-many relationship (each person can have many boundaries, and each boundary can have many persons). I am trying to create a list of what boundaries Person Fred doesn't have a relationship too. Person *person = [Person MR_findFirstByAttribute:@"name" withValue:@"Fred"]; DLog(@"person.boundaries.count: %d", person.boundaries.count); NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY persons != %@", person]; DLog(@"testBoundaries.count: %d", [Boundary MR_countOfEntitiesWithPredicate:predicate]); I have 47 boundaries in

NSPredicate omits special characters like á â á in filterContentForSearchText method

风格不统一 提交于 2019-12-02 07:35:07
I am developing an app with an UISearchBar and I need to filter some names with special characters like à, è, ê and so on.. but if I don't type the correct string with the special character it doesn't appear. Ex: If I am looking for cómodo word I can't find this word if I don't type exactly có How could I get that word without type that special characters? for example typing just co . This is my NSPredicate : NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.word BEGINSWITH[c] %@", searchText]; Thank you Ignore diacrtical needs to be specified, "[cd]" instead of "[c]". See

NSPredicate use array as filter

别等时光非礼了梦想. 提交于 2019-12-02 07:03:41
I'm trying to use an array as a filter to search Core Data. The values that the fetchRequest returns should have an ID that is in the predicate's array. let arrayOfFavoriteStampIDS = [302,2300,2309] fetchRequest.predicate = NSPredicate(format: "itemID IN %i", argumentArray: arrayOfFavoriteStampIDS) Almost fetchRequest.predicate = NSPredicate(format: "itemID IN %@", arrayOfFavoriteStampIDS) argumentArray means something else for example fetchRequest.predicate = NSPredicate(format: "itemID == %i OR itemID == %i OR itemID == %i", argumentArray:arrayOfFavoriteStampIDS) In this case each item in

NSPredicate use array as filter

China☆狼群 提交于 2019-12-02 06:50:33
问题 I'm trying to use an array as a filter to search Core Data. The values that the fetchRequest returns should have an ID that is in the predicate's array. let arrayOfFavoriteStampIDS = [302,2300,2309] fetchRequest.predicate = NSPredicate(format: "itemID IN %i", argumentArray: arrayOfFavoriteStampIDS) 回答1: Almost fetchRequest.predicate = NSPredicate(format: "itemID IN %@", arrayOfFavoriteStampIDS) argumentArray means something else for example fetchRequest.predicate = NSPredicate(format: "itemID