nspredicate

fetch request for entity.attribute == @“somevalue”

◇◆丶佛笑我妖孽 提交于 2019-12-09 11:55:19
问题 How do I setup a fetch request to only pull the data from an entity's attribute with one particular value? This is the basic code I've used before. -(void)fetchResults { NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:self.entityDescription.name]; NSString *cacheName = [self.entityDescription.name stringByAppendingString:@"Cache"]; // predicate code if (self.predicate != nil) { [fetchRequest setPredicate:self.predicate]; } // end of predicate code NSSortDescriptor

NSPredicate 'OR' filtering based on an NSArray of keys

谁都会走 提交于 2019-12-09 10:26:57
问题 Consider the following NSArray: NSArray *dataSet = [[NSArray alloc] initWithObjects: [NSDictionary dictionaryWithObjectsAndKeys:@"abc", @"key1", @"def", @"key2", @"hij", @"key3", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"klm", @"key1", @"nop", @"key2", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"qrs", @"key2", @"tuv", @"key4", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"wxy", @"key3", nil], nil]; I am able to filter this array to find dictionary objects that contain the

Can't pass Date to NSPredicate(format: …) without “as CVarArg”

一个人想着一个人 提交于 2019-12-09 07:38:22
问题 Is this how I'm supposed to pass a Date to NSPredicate.init(format predicateFormat: String, arguments argList: CVaListPointer) . let endDate = Date() NSPredicate(format: "endDate == %@", endDate as CVarArg) It looks kinda clumsy, and I suspect I'm doing something wrong. 回答1: The %@ format expect a Foundation object as argument, compare "Predicate Format String Syntax" in the "Predicate Programming Guide". Therefore you have to cast the overlay type Date back to its Foundation counterpart

NSPredicate on NSDictionary

 ̄綄美尐妖づ 提交于 2019-12-09 05:26:54
问题 I'm trying to make sections in a table view based on the alphabet and sort my entries alphabetically under these sections. I have collected the first letter in every entry of bandsArray in bandsArrayIndex and I'm now trying to use NSPredicate to count how many of each letter there are. I'm doing this by following this guide. They are using an NSArray and I'm using an NSDictionary and can't seem to get it to work. Can anyone help me out? The application crashes when trying to show the view

NSPredicate, get results with a subset of one-to-many relationship

十年热恋 提交于 2019-12-09 01:41:13
问题 I'mm working around with Core Data and NSFetchedResultsController . My Data Model looks like this: Product with one-to-many relationship called dataLines . The dataLine entity has a property name theWeek . I want to fetch all Product where dataLines.theWeek == someValue . This is easily done with a subquery. But this returns all dataLines. Is it possible to create a NSPredicate that returns the Product and a subset if dataLines only with the dataLines == someValue ? 回答1: What you want to

NSPredicate- For finding events that occur between a certain date range

冷暖自知 提交于 2019-12-09 00:14:04
问题 This is a little more complicated then just NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate >= %@ AND endDate <= %@", startDay,endDay]; I'm building a calendar app and I need to pull events out of my core data store that occur on a given day. However, it's possible for an event to start/end on a different day then the day I'm trying to display, e.g. My Date Range (Start = 2011-12-02 00:00:00 to End = 2011-12-02 23:59:59) An Event (Start = 2011-12-01 23:00:00 to End =

Difference between ALL , ANY and SOME operators in NSPredicate

梦想的初衷 提交于 2019-12-08 17:09:47
问题 I'm really struggling to understand these 3. It looks like ANY and SOME do the same thing, but I don't see the difference with ALL . 回答1: Let's have a list of groups. Every group has members of type person. Every person has an age. ALL members.age > 30 means that you will find a group with members that are all older than 30. You will not find a group with at least one single member being 30 or younger. ANY members.age > 30 means that you will find a group with at least one member older than

create a Compound Predicate in coreData xcode iphone

泄露秘密 提交于 2019-12-08 17:02:06
问题 HI i am working on the core data with 3 entities (Class,Students,ExamRecord) and their relations area as : Class<------>> Students <------> ExamRecord I created a predicate for fetching list of students for class 5th. NSString * fmt2 = @"studentsToClass.className=%@"; NSPredicate * p2 = [NSPredicate predicateWithFormat:fmt2,@"5th",nil]; with this i am getting all students of class 5th Now i also want to apply another filter on the Students fetched. Fetch students whose Exam Record "result" is

Filtering NSMutableArray of NSDictionary with NSPredicate

梦想与她 提交于 2019-12-08 11:43:02
问题 I'm having an NSObject entity for storing some data like name, id from server NSObject file looks like below, @interface MyEntity : NSObject @property(nonatomic,strong)NSString *userId; @property(nonatomic,strong)NSString *userName; - (id)initWithJSON:(NSDictionary *)dataDict; @end - (id)initWithJSON:(NSDictionary *)dataDict { if (self = [super init]) { self.userId = [dataDict objectForKeyNotNull:@"userId"] ; self.userName = [dataDict objectForKeyNotNull:@"userName"] ; } return self; } I'm

iphone & Objective C - Filtering an array using NSPredicate?

瘦欲@ 提交于 2019-12-08 09:47:57
问题 I have an array of objects (Users) each user has an nsset named "devices" Is it possible to filter so the array returns all users who have a device with a specific name. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"devices.category==%@", @"mobile"]; myArray = [allUsersArray filteredArrayUsingPredicate:predicate]; 回答1: You've almost got it, just a little bit off. Each User has a set of Devices . This means that when you invoke [aUser valueForKeyPath:@"devices.category"] , it's