nspredicate

Error: 'Unsupported predicate in fetch options: mediaType == 2'

时光怂恿深爱的人放手 提交于 2019-12-03 01:59:52
I'm trying to use smartAlbum to generate an array of either only videos or only photos or both. You can see my code below: PHFetchResult *collectionList = [PHCollectionList fetchMomentListsWithSubtype:PHCollectionListSubtypeMomentListCluster options:nil]; PHFetchOptions *options = nil; if (self.xSelected) { options = [[PHFetchOptions alloc] init]; options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; options.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d",PHAssetMediaTypeImage]; } if (self.ySelected) { options = [[PHFetchOptions

NSPredicate Sort Array and Order DESC

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an NSMutableArray containing TBPosts that I would like to filter in descending order according to the commentsCount and likesCount of the TBPost . Initially, the first object in the filtered array will be the object with the largest number of comments and likes, which can be worked out by adding the two together. So I tried the following query and receive an Unable to Parse error. Please can you tell me where I am going wrong? [ posts filterUsingPredicate :[ NSPredicate predicateWithFormat :@ "post.commentsCount + post

NSPredicate BETWEEN with NSDate causes -[__NSDate constantValue]: unrecognized selector sent to instance 0x1e7ff0

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to fetch from Core Data records that have a startTime between two dates. Here's my code: NSDate *today = [NSDate date]; NSDate *distantFuture = [NSDate distantFuture]; // Create the predicate NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startTime BETWEEN %@", [NSArray arrayWithObjects:today, distantFuture, nil]]; NSLog(@"today: %@, distantFuture: %@", today, distantFuture); NSLog(@"predicate: %@", predicate); // Add the predicate to the fetchRequest [[[self fetchedResultsController] fetchRequest] setPredicate

NSPredicate on array of arrays

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array, that when printed out looks like this: ( ( databaseVersion, 13 ), ( lockedSetId, 100 ) ) Would it be possible to filter this using an NSPredicate (potentially by the index in the array). So something like: give me all rows where element 0 is 'databaseVersion'? I know that if I had an array of dictionaries I could do this with a predicate similar the one found here , but I found that when using dictionaries and storing a large amount of data, my memory consumption went up (from ~80mb to ~120mb), so if possible I would to keep

NSPredicate for property of object in NSArray of NSArray

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 : NSObject @property (nonatomic, copy) NSString

Regex for an email address doesn't work

萝らか妹 提交于 2019-12-03 00:50:22
I'm trying to check if some email address is correct with the following code : NSPredicate *regexMail = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*@.*\..*'"]; if([regexMail evaluateWithObject:someMail]) ... But the "\." doesn't seem to work since the mail "smith@company" is accepted. Besides, I have the following warning : "Unknown escape sequence" Edit : I'm programming in Objective-C for iPhone. Thanks Craig Trader You cannot correctly validate an email address with regular expressions alone. A simple search will show you many articles discussing this. The problem lies with the

CoreData: Find minimum of calculated property

╄→гoц情女王★ 提交于 2019-12-03 00:49:52
Say I have a CoreData entity "Point" with two properties x and y (both NSNumber). How would a NSPredicate need to look like to let me find the closest Point to say a,b? for distance = sqrt((x-a) (x-a)+(y-b) (y-b)) While I could define a transient property that calculates a distance to a predefined point I can't see how I could programmatically change that point when launching a fetchrequest. Any help would be greatly appreciated. Sorry, but doing arithmetic in an NSPredicate isn't supported. Only comparison operators can be used. And the news gets worse. You can't use a transient property in

谓词 NSPredicate

匿名 (未验证) 提交于 2019-12-03 00:32:02
NSPredicate 主要是用来查询、条件过滤; 最常用的场景就是在自定义的数据模型对象中根据条件来查询相关信息,例如在手机通讯录中根据个人信息的Model所包含的name属性,来进行搜索 * 简言之* NSPredicate可以判断某个对象的某一个属性是否符合某一条件 =、==:判断两个表达式是否相等,在谓词中=和==是相同的意思都是判断,不是赋值。 >=,=>:判断左边表达式的值是否大于或等于右边表达式的值 <=,=<:判断左边表达式的值是否小于或等于右边表达式的值 >:判断左边表达式的值是否大于右边表达式的值 <:判断左边表达式的值是否小于右边表达式的值 !=、<>:判断两个表达式是否不相等 BETWEEN:BETWEEN表达式必须满足表达式 BETWEEN {下限,上限}的格式,要求该表达式必须大于或等于下限,并小于或等于上限 NSPredicate *predicate = [NSPredicate predicateWithFormat:@ "SELF BETWEEN {100, 200}" ]; BOOL isBool = [predicate evaluateWithObject:testNumber]; AND、&&:逻辑与,要求两个表达式的值都为YES时,结果才为YES。 OR、||:逻辑或,要求其中一个表达式为YES时,结果就是YES NOT、 !:逻辑非

Unable to query for date using NSPredicate in Swift

核能气质少年 提交于 2019-12-02 22:02:33
I'm trying to make a fetch for dates later than a specific date. My predicate is as follows: NSPredicate(format: "date > \(currentDate)") When I executed the fetch request I caught an exception: 'Unable to parse the format string "date > 2015-07-08 03:00:00 +0000"' I thought I could make a query like that. What am I doing wrong? NSPredicate(format:_:) takes a format string and a list of arguments, but you're passing a simple string. This doesn't work, since this initializer doesn't just call stringWithFormat: on the parameters, but actually looks at the arguments' type information as it's

Using NSPredicate to filter array of arrays

我的未来我决定 提交于 2019-12-02 21:07:50
I have the following situation: NSArray( NSArray( string1, string2, string3, string4, string5, ) , NSArray( string6, string7, string8, string9, string10, ) ) Now I need a predicate that returns the array that contains a specific string. e.g. Filter Array that contains string9 -> I should get back the entire second array because I need to process the other strings inside that array. Any ideas? Just for completeness: It can be done using predicateWithFormat: : NSArray *array = @[ @[@"A", @"B", @"C"], @[@"D", @"E", @"F"], ]; NSString *searchTerm = @"E"; NSPredicate *predicate = [NSPredicate