nspredicate

Searching/Filtering a custom class array with a NSPredicate

心不动则不痛 提交于 2019-12-18 04:54:53
问题 I have a array that contains objects of a custom class, and I would like to filter the array based on if one of the classes attributes contains a custom string. I have a method that is passed the attribute that I want to be searched (column) and the string that it will search for (searchString). Here is the code I have: NSPredicate *query = [NSPredicate predicateWithFormat:@"%K contains %K", column, searchString]; NSMutableArray *temp = [displayProviders mutableCopy]; [displayProviders

Querying Core Data for Specific Attributes when Creating New Objects and returning the object if it exists, or creating a new one if it does not

﹥>﹥吖頭↗ 提交于 2019-12-18 04:26:09
问题 I have a problem checking whether a particular attribute of an Entity exists in the Core Data Database (through predicates) before creating a new object; if the object exists, I'd rather return it than create a new object. I have a simple App which has a table view with a plus button in the Navigation Bar; the user clicks that and is presented with a View Controller with 4 text fields. They fill in that information, press save and it gets saved to Core Data and displayed in the TableView

iPhone SDK Core Data: Fetch all entities with a nil relationship?

早过忘川 提交于 2019-12-18 03:38:08
问题 I have a core data project that has Books and Authors. In the data model Authors has a to-many relationship to Books and Books has a 1-1 relationship with Authors. I'm trying to pull all Books that do not have an Author. No matter how I try it, no results are returned. In my predicate I've also tried = NIL, == nil, == NIL. Any suggestions would be appreciated. // fetch all books without authors - (NSMutableArray *)fetchOrphanedBooks { NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]

Iphone NSPredicate how to do an INNER JOIN?

只愿长相守 提交于 2019-12-17 19:26:20
问题 I have been looking thru the documentation and some other posts in this site, but I simply cannot understand how to work this out, which is actually very simple in SQL. Basically I have 2 entities Instruments and Deals. And the "Deals" use an "Instrument" to perform a desired operation. Now I want to list Deals attributes and the Instrument attributes that were used for this deal. So in SQL i would do: SELECT * FROM Instruments INNER JOIN Deals ON Instruments.ID = Deals.InstrumentID How would

NSArray with NSPredicate using NOT IN

狂风中的少年 提交于 2019-12-17 17:36:52
问题 I have an NSArray that I want to filter out certain objects using an NSPredicate, I was hoping I could use NOT IN since I saw that I can easily do an IN. So I have my array: self.categoriesList Then I get the values I want to remove: NSArray *parentIDs = [self.cateoriesList valueForKeyPath:@"@distinctUnionOfObjects.ParentCategoryID"]; This gives me a list of ParentCategoryID's for categories I DO NOT want to display, so I figure I can use an NSPredicate to remove them: self.cateoriesList =

iPhone - getting unique values from NSArray object

和自甴很熟 提交于 2019-12-17 17:24:31
问题 I have an NSArray formed with objects of a custom class. The class has 3 (city, state, zip) string properties. I would like to get all unique state values from the array . I did read through the NSPredicate class but couldn't make much of how to use it in this case. The only examples I could find were for string operations. Can someone please help me out? 回答1: The totally simple one liner: NSSet *uniqueStates = [NSSet setWithArray:[myArrayOfCustomObjects valueForKey:@"state"]]; The trick is

正则表达式匹配异常导致崩溃的问题

谁说我不能喝 提交于 2019-12-17 12:15:36
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 今天写一个正则表达式,完成这样的需求:对输入的文字进行检查,要求输入的内容允许包含小写字母、文字和_-./这四个字母。 于是我写的代码如下: // 用户名是否有效 +( BOOL ) validateUserName:( NSString *)name { NSPredicate * predicate = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" , @"[a-z0-9_-./]*" ]; BOOL bMatch = [predicate evaluateWithObject :name]; return bMatch; } 但是运行程序的时候对输入的进行校验时,崩溃 崩溃内容如下: Can't do regex matching, reason: Can't open pattern U_REGEX_INVALID_RANGE (string 1111, pattern [a-z0-9_-./]*, case 0, canon 0) 然后我把写的这则表达式放到网上的正则表达式检查工具进行检测,发现“-”这个连接符需要转义。否则就是错误的正则表达式。 于是我进行修改一下,就OK了。 // 用户名是否有效 +( BOOL )

Quick Explanation of SUBQUERY in NSPredicate Expression

倾然丶 夕夏残阳落幕 提交于 2019-12-17 05:02:28
问题 There appears to be zero documentation about the SUBQUERY keyword from Apple and I can't find a simple explanation about it on SO or on Google. It's a conspiracy! ;) Please , could someone from the inner-circle please just provide a quick explanation of its syntax so I can use it? SUBQUERY(Bs, $x, $x IN %@) Thanks 回答1: This is what a subquery evaluates to. (Found from this mailing list thread, the #1 hit for “NSPredicate subquery” in Google.) That bit of documentation also explains how the

Core Data NSPredicate “deleted == NO” does not work as expected

耗尽温柔 提交于 2019-12-17 03:20:22
问题 I am using UIManagedDocument with Parent Child context. In my child context I do the following Code 1 NSSet *results = [self.event.memberships filteredSetUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { return ([[evaluatedObject deleted] boolValue] == NO); }]]; Above code returns the expected results (only Not deleted members for the event). Code 2 But this code does not. It fetches all records. NSPredicate *predicate = [NSPredicate

obj c -get list of indexes in NSArray from NSPredicate

自作多情 提交于 2019-12-14 04:26:02
问题 I have an array of car and I am filtering it based on objects containing the letter i . NSMutableArray *cars = [NSMutableArray arrayWithObjects:@"Maruthi",@"Hyundai", @"Ford", @"Benz", @"BMW",@"Toyota",nil]; NSString *stringToSearch = @"i"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",stringToSearch]; // if you need case sensitive search avoid '[c]' in the predicate NSArray *results = [cars filteredArrayUsingPredicate:predicate]; results contains Maruthi