nspredicate

Word boundaries (\b) in NSPredicate causing NSFetchRequest to return no managed objects

自作多情 提交于 2019-12-24 08:12:51
问题 Using Core Data w/a sqlite store on iPhone.... I've got a bunch of comic book image entities, each with a string that includes the comic's issue#, e.g.: image.imageTitle = @"Issue 12: Special Edition"; Part of the UI allows the user to type in an issue number to jump to the next issue. My initial code for this was sloooooooow because imageAtIndex: queries Core Data for one object at a time. Over several hundred issues, it could take upwards of 40 seconds just to get through the first loop!

How to setup NSPredicate and NSEntityDescription in Coredata to do complicated SQL query

三世轮回 提交于 2019-12-24 07:10:15
问题 I know how to create NSPredicate to do sql like "SELECT * FROM DRINK" . But how about this query: "SELECT I.name, D_I.amount FROM DRINK_INGREDIENT D_I, DRINK, INGREDIENT I WHERE D_I.drinkID=1 AND DRINK.drinkID=1 AND I.ingredientID = D_I.ingredientID;" How do I even set the NSEntityDescription, and NSPredicate for this kind of query? 回答1: Typically with Core Data you will design and use a data model that meets your needs. You should not think about it in terms of SQL--it does not even have to

NSPredicate Character and/or Letter Substitutions

血红的双手。 提交于 2019-12-24 07:09:42
问题 I've seen some, somewhat, similar questions about filtering out special characters in a predicate - but nothing suitable for my needs. I'm not really sure if what I want to do is even possible but I'll put it to the community instead: I'm working with strings of pronunciations for a dictionary that contain a lot of IPA characters for instance: ȵ ɕ ŋ Ẓ What I would like to do is set up some substitutions for these characters, something like: n=ȵ x=ɕ ng=ŋ r=Ẓ in a search predicate so that a

NSPredicate with NSDate filtering by day/month but not year

谁说胖子不能爱 提交于 2019-12-24 06:58:47
问题 I need to create a predicate which needs to filter a list of objects using the property creationDate which is a NSDate object. I want to obtain the list of objects that have the same day and month, but not the same year. Practically, I want the objects that occurred today (as day/month) in the past. How can I create this predicate? For example : today is July 27th 2016 and I want all the objects that have July 27th as creationDate. 回答1: First, to extract a day and month from a date...

Why is this predicate format being turned into '= nil'

倖福魔咒の 提交于 2019-12-24 05:03:10
问题 It was suggested that this thread is an exact duplicate of my question however, my app wasn't crashing and I'm not migrating to Swift 3. It just wasn't returning any results. So the solution is essentially the same but the behavior on which my question is based is quite different. After reading many threads this morning I'm pretty confident this code is correct and should work: func fetchUnits(weightUnitUid: Int? = nil) -> [WeightUnit] { let fetchRequest = NSFetchRequest(entityName:

Why is this predicate format being turned into '= nil'

≡放荡痞女 提交于 2019-12-24 05:02:37
问题 It was suggested that this thread is an exact duplicate of my question however, my app wasn't crashing and I'm not migrating to Swift 3. It just wasn't returning any results. So the solution is essentially the same but the behavior on which my question is based is quite different. After reading many threads this morning I'm pretty confident this code is correct and should work: func fetchUnits(weightUnitUid: Int? = nil) -> [WeightUnit] { let fetchRequest = NSFetchRequest(entityName:

NSPredicate for property of object in NSArray of NSArray

风流意气都作罢 提交于 2019-12-24 03:44:09
问题 I have an objects like the below structure: Transaction has an array of Items. Item has an array of SubItems @interface Transaction : NSObject @property (nonatomic, copy) NSString *id; @property (nonatomic, assign) NSInteger status; @property (nonatomic, strong) NSArray *items; // array of Item @end @interface Item : NSObject @property (nonatomic, copy) NSString *identifier; @property (nonatomic, assign) NSInteger price; @property (nonatomic, strong) NSArray *subitems; @end @interface SubItem

how to solve NSPredicate error 'Can't use in/contains operator with collection 8 (not a collection)

五迷三道 提交于 2019-12-24 03:09:32
问题 I tried to predicate my coredate based on the mood on the initial queries all the moods are set to 8. I will be calling from 0 - 7 every sec to update the tableview. but I got Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use in/contains operator with collection 8 (not a collection)' Should I use CONTAINS or other operator to predicate? NSString* filter = @"%K CONTAINS[cd] %@"; NSPredicate *getMoodPred = [NSPredicate predicateWithFormat:filter, @"mood"

NSPredicate to compare Int32

匆匆过客 提交于 2019-12-24 01:18:49
问题 elementFetch.predicate = NSPredicate(format: "pageId = %@",(Int32(pagesFromDb.first?.pageId)) !) var Data = try moc.fetch(elementFetch as! NSFetchRequest<NSFetchRequestResult>) as! [Element] I tried it with %I , %d , and converting to Int or number, nothing works. Please suggest how to do this. 回答1: This is because you are using the operator %@ which is for Strings. For integers use %i (not %I ) as follows: elementFetch.predicate = NSPredicate(format: "pageId = %i", pagesFromDb.first?.pageId)

Filter NSArray with NSPredicate

笑着哭i 提交于 2019-12-24 01:17:01
问题 I want to filter an array of User objects ( User has fullname , user_id and some more attributes..) according to firstName or lastName that begin with some string. I know how to filter according to one condition: NSPredicate* predicate = [NSPredicate predicateWithFormat:@"firstName BEGINSWITH[cd] %@", word]; NSArray* resArr = [myArray filteredArrayUsingPredicate:predicate]; this will give me all the users that has a firstName that starts with "word". But what if I want all the users that has