nspredicate

SwiftUI View and @FetchRequest predicate with variable that can change

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 09:56:06
问题 I have a view showing messages in a team that are filtered using @Fetchrequest with a fixed predicate 'Developers'. struct ChatView: View { @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \Message.createdAt, ascending: true)], predicate: NSPredicate(format: "team.name == %@", "Developers"), animation: .default) var messages: FetchedResults<Message> @Environment(\.managedObjectContext) var viewContext var body: some View { VStack { List { ForEach(messages, id: \.self) { message in

NSPredicate comparing transformed CLPlacemark with another CLPlacemark

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm saving CLPlacemark in Core data using NSValueTransformer . (so it's saved as NSData ) However I've come to a point where I need to filter the saved objects based on another CLPlacemark object. I've tried this, it doesn't work: NSExpression *exprPath = [NSExpression expressionForKeyPath:@"placemark"]; NSExpression *exprKeyword = [NSExpression expressionForConstantValue:[NSKeyedArchiver archivedDataWithRootObject:placemark]]; NSPredicate *predicate = [NSComparisonPredicate predicateWithLeftExpression:exprPath rightExpression:exprKeyword

Core data to-many NSPredicate with AND

谁说我不能喝 提交于 2019-12-03 08:54:30
I'm trying to write a query for the find-as-you-type search bar. What I want to do is query "Kind", and return any Kinds for which there is a LocalName with ('name' LIKE %@ AND localeIdentifier == %@). If I'm only searching the names (so ignoring the localeIdentifier), I could do something like this: ANY localized.name LIKE %@ What I want is something more like ANY localized.(name LIKE %@ AND localeIdentifier == %@) To sum up, searching "Kind", any one item in the to-many relationship "localized" should match both name and localeIdentifier. Any ideas for the correct syntax of this? What you

NSPredicate versus NSString: Which is better/faster for finding superstrings?

两盒软妹~` 提交于 2019-12-03 08:40:25
I have a large number of strings that I'm searching to see if a given substring exists. It seems there are two reasonable ways to do this. Option 1: Use the NSString method rangeOfSubstring and test whether .location exists: NSRange range = [string rangeOfSubstring:substring]; return (range.location != NSNotFound); Option 2. Use the NSPredicate syntax CONTAINS : NSPredicate *regex = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@", substring]; return ([regex evaluateWithObject:string] == YES) Which method is better, or is there a good Option 3 that I'm completely missing? No, I'm not sure

Can&#039;t pass Date to NSPredicate(format: …) without “as CVarArg”

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 NSDate : let endDate = Date() let pred = NSPredicate

NSPredicate - Unable to parse the format string [duplicate]

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Creating NSPredicate dynamically by setting the key programmatically 2 answers I am trying to write a NSPredicate to fetch rows with my_column value with this string " 193e00a75148b4006a451452c618ccec " and I get the below crash. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "my_column=193e00a75148b4006a451452c618ccec"' My predicate statement fetchRequest.predicate=[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"%@==\"

Unable to query for date using NSPredicate in Swift

给你一囗甜甜゛ 提交于 2019-12-03 08:21:54
问题 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? 回答1: 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

What are the difference and use-cases for va_list, CVaListPointer, AnyObject …, CVarArgType?

只谈情不闲聊 提交于 2019-12-03 08:13:04
问题 Question Can someone please explain the differences between these argument types? Furthermore, if possible please supply appropriate use-cases using code (it's worth a 1000 words). Nota bene Please let me know in the comments if there is any requirement for more information. Background I am attempting to understand any differences between the following constructs and understand the appropriate use-cases (with examples if there are any). I've searched SO, Google, et, al. (blogosphere) without

NSPredicate on NSDictionary

╄→гoц情女王★ 提交于 2019-12-03 07:32:04
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 with the table view in it. In Debugger Console the following error is shown: * Terminating app due to

How to improve Core Data performance?

风格不统一 提交于 2019-12-03 05:11:18
问题 My app has a UISearchBar allowing user to enter search keywords. Each keystroke executes a Core Data query in order to display the results as text in search bar changes. The problem is that search bar keystrokes are lagging pretty bad... surely because of slow fetching. Any ideas how to improve the performance? My Core Data is backed with sqlite data store which contains 1000 objects. // searchKeyword is the string appears in UISearchBar // Both title and author may contain several words so I