nspredicate

NSPredicate: how to treat strings as numbers?

有些话、适合烂在心里 提交于 2019-12-01 23:42:01
问题 I am building a compound NSPredicate to make a fetch request, using core data on sqlite, within iOS app. Everything already works fine, but I am not being able to include the last condition. The reason is quite simple: I need to check if the value, stored as a string, is within certain float bounds. The problem is that the conditions are checked on alphabetical order basis, and not according its float value. Here it is the code: NSString * conditionToBeAdded = [NSString stringWithFormat:@" &&

NSPredicate in NSFetchedResultsController doesn't use Category's getter

左心房为你撑大大i 提交于 2019-12-01 22:12:38
问题 I have an attribute with an int_32 property called seconds. In a category, I restate the property as readonly and override the getter to create it from other properties. The issue is when I use [NSPredicate predicateWithFormat:@"SELF.seconds > %i"]; The predicate does not work because the getter is not called by the predicate. It is called in my other code just fine, just not in the predicate. Anyone know why this would happen or how to get around this problem? (besides recreating

NSPredicate: how to treat strings as numbers?

霸气de小男生 提交于 2019-12-01 21:27:30
I am building a compound NSPredicate to make a fetch request, using core data on sqlite, within iOS app. Everything already works fine, but I am not being able to include the last condition. The reason is quite simple: I need to check if the value, stored as a string, is within certain float bounds. The problem is that the conditions are checked on alphabetical order basis, and not according its float value. Here it is the code: NSString * conditionToBeAdded = [NSString stringWithFormat:@" && (%@ >= \"""%@\""") && (%@ <= \"""%@\""")", propertyName, myMinFloat, propertyName, myMaxFloat];

Filter realm objects to only get one (distinct) object by attribute

ぐ巨炮叔叔 提交于 2019-12-01 21:26:39
Let me explain first cause title may be a bit confusing. Say I have this realm objects of type Movie: Movie1(id: 0, genre: "horror") Movie2(id: 1, genre: "horror") Movie3(id: 3, genre: "sci-fi") What I need to do is get the first for every genre (in this case Movie1 and Movie3 ) I'd like to do it w/o loops using only realm + NSPredicate , so the performance is better, but I'm a bit stuck there... So far what I got is this: Realm().objects(Movie.self).sorted(byKeyPath: id, ascending: true) .value(forKeyPath: "@distinctUnionOfObjects.genre") This returns me an array with ("horror", "sci-fi") and

How to prevent “SQL Injection” in Core Data?

依然范特西╮ 提交于 2019-12-01 21:20:20
I am building a pretty complex predicate in several iterations, and want to supply the matching values right away in the predicate. Instead of: [NSPredicate predicateWithFormat:@"departmentName like[c] %@"]; I want to do: NSString *str = [NSString stringWithFormat:@"departmentName like[c] '%@'", departmentName]; [NSPredicate predicateWithFormat:str]; Since this is a dumb substitution, I guess it's possible to "hack" the predicate accidently by entering garbage. I couldn't find anything that would "magically quote" that value for me. Reason is, that I need to build up a complex predicate in

NSPredicate in NSFetchedResultsController doesn't use Category's getter

為{幸葍}努か 提交于 2019-12-01 20:56:54
I have an attribute with an int_32 property called seconds. In a category, I restate the property as readonly and override the getter to create it from other properties. The issue is when I use [NSPredicate predicateWithFormat:@"SELF.seconds > %i"]; The predicate does not work because the getter is not called by the predicate. It is called in my other code just fine, just not in the predicate. Anyone know why this would happen or how to get around this problem? (besides recreating NSFetchedResultsController). The predicate is converted into SQL and run on the store. It doesn't run any of your

Show distinct results in fetch request, group by an attribute and calculate the total for that attribute

一世执手 提交于 2019-12-01 20:41:25
Scenario: I have an expense tracking iOS Application and I have a view controller called "DashBoardViewController" (table view controller - with FRC) which would basically categorize my expenses/incomes for a given week, a month, or year and display it as the section header title for example : (Oct 1- Oct 7, 2012) and it shows expenses/incomes ROWS and related stuff according to that particular week or month or year. My Question: What I want to accomplish is : Suppose I save 3 new expenses with SAME category named "Auto" on three different dates(11 nov, 14 nov, 16 nov, 2012 respectively). In

XCTest-iOS单元测试框架

自作多情 提交于 2019-12-01 20:24:41
Xctest 是iOS的单元测试框架,有objective-c和swift两种语言可以选择 Xcuitest 是iOS的UI测试框架 XCTest 官方文档地址: https://developer.apple.com/documentation/xctest XCTest 框架类似于python中的unit test框架,声明一个测试case继承XCTestCase和测试方法,测试方法以test开头,然后执行。 相关类介绍: Class XCTest XCTest类提供XCTestCase和XCTestSuite用于创建、管理和执行测试的共享功能。在大多数情况下,在项目中定义测试时,应该直接子类化XCTestCase。 包含了以下属性: name: test 的 name testCaseCount: case个数 testRun: XCTestRun对象来执行test testRunClass: 运行测试时实例化的XCTestRun子类,以保存测试结果。 包含了以下方法: perform( XCTestRun ): 执行一个特定的测试 run():创建testRunClass指定的类的实例,并将其作为参数传递给执行perform(_:)方法。 还包含了一系列的断言方法 Class XCTestCase 具体的属性和方法看文档,主要包含代码块性能检测,异步测试(例如打开文档

NSPredicate to get children's children's

房东的猫 提交于 2019-12-01 19:46:50
I want to fetch all the treatments, that are children of this List object. I am not sure if it can be done. I have a TableView showing all the patients of a list. Each patient can have many treatments. I have a reference to the current list, and want to use that to somehow find the childrens children. Thank you Use a fetch request for the "Treatment" entity with the predicate [NSPredicate predicateWithFormat:@"ofPatient.ofList = %@", currentList] using the inverse relationships from "Treatment" -> "Patient" -> "List". 来源: https://stackoverflow.com/questions/18697355/nspredicate-to-get

NSPredicate syntax for DATEADD?

为君一笑 提交于 2019-12-01 19:33:07
is there a way to do a DateAdd or a DateDiff function on an NSPredicate? Thank you, Jose. Actually, there is! It's a roundabout way of doing it, because NSPredicate doesn't support it directly (ie, you can't just + anInterval to an NSDate ). Fortunately, you can do it, and luckily for you, I just figured it out about 2 days ago. To clarify: I'm assuming you're asking for something like: "an object has a date property. I want to see if this date property is some arbitrary interval before/after another date". If that's what you mean, then yes you can do it. If that's not what you mean, then