nspredicate

How to use NSPredicate for whether a List of Int contains a Int number?

↘锁芯ラ 提交于 2021-02-17 03:56:50
问题 I got a Realm model Person who has a tag property. let tags = List<Int>() Now, I would like to perform a search like this realm.objects(Person.self).filter(NSPredicate(format: "\(tagID) IN tags")) // "0 IN tags" Error: Terminating app due to uncaught exception 'Invalid value', reason: 'Expected object of type (null) for property 'tags' on object of type 'Person', but received: 0' 回答1: As stated in David's comment, you cannot filter on a list of primitives. You can only filter on List's that

How do I show 2 different color dots for a date using FSCalendar?

给你一囗甜甜゛ 提交于 2021-02-10 23:43:09
问题 Beginner programmer here. I am trying to show two different color dots if there is a negative AND a positive transaction for that date. Here is my code. It only shows one dot. func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int { let incomeTransaction = realm.objects(Transaction.self).filter(positiveTransactionPredicate(date: date)) let expenseTransaction = realm.objects(Transaction.self).filter(negativeTransactionPredicate(date: date)) for _ in incomeTransaction {

How do I show 2 different color dots for a date using FSCalendar?

南笙酒味 提交于 2021-02-10 23:41:46
问题 Beginner programmer here. I am trying to show two different color dots if there is a negative AND a positive transaction for that date. Here is my code. It only shows one dot. func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int { let incomeTransaction = realm.objects(Transaction.self).filter(positiveTransactionPredicate(date: date)) let expenseTransaction = realm.objects(Transaction.self).filter(negativeTransactionPredicate(date: date)) for _ in incomeTransaction {

How do I show 2 different color dots for a date using FSCalendar?

一个人想着一个人 提交于 2021-02-10 23:40:43
问题 Beginner programmer here. I am trying to show two different color dots if there is a negative AND a positive transaction for that date. Here is my code. It only shows one dot. func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int { let incomeTransaction = realm.objects(Transaction.self).filter(positiveTransactionPredicate(date: date)) let expenseTransaction = realm.objects(Transaction.self).filter(negativeTransactionPredicate(date: date)) for _ in incomeTransaction {

How do I show 2 different color dots for a date using FSCalendar?

落花浮王杯 提交于 2021-02-10 23:40:23
问题 Beginner programmer here. I am trying to show two different color dots if there is a negative AND a positive transaction for that date. Here is my code. It only shows one dot. func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int { let incomeTransaction = realm.objects(Transaction.self).filter(positiveTransactionPredicate(date: date)) let expenseTransaction = realm.objects(Transaction.self).filter(negativeTransactionPredicate(date: date)) for _ in incomeTransaction {

How to filter an array using NSPredicate in swift 3

自闭症网瘾萝莉.ら 提交于 2021-02-08 08:43:49
问题 I have an arraycontaining several dictionaries. { DisplayName?:"Name of the employee" Age:28 Department:"Dept 2" } I just converted my objective-c code into swift and trying to filter like this. let exists = NSPredicate(format: "DisplayName2 CONTAINS[cd] \(searchText!)") let aList: Array<Any> = arrayDirectory.filter { exists.evaluate(with: $0) } if(aList.count>0) { arrayDirectory=aList facesCarousel.reloadData() } But I am always getting the aList count as 0. It seems like not filtering my

Fetching child sum from Core Data

ⅰ亾dé卋堺 提交于 2021-02-07 19:55:04
问题 Lets say I have three Entitys. Person: name address (to-many-salary) and (to-many-loans) Salary: income tax Rel: (to-one-Person) Bills amount Rel: (to-one-person) How do I perform a fetch that have a result like this: John Doe, SUM>income, SUM>amount Eva Doe, SUM>income, SUM>amount Using Swift 回答1: This is probably most easily done using Key Value Coding "collection operators" (see here) rather than a fetch. For each person : let name = person.name let totalIncome = person.valueForKeyPath(

Fetching child sum from Core Data

徘徊边缘 提交于 2021-02-07 19:54:16
问题 Lets say I have three Entitys. Person: name address (to-many-salary) and (to-many-loans) Salary: income tax Rel: (to-one-Person) Bills amount Rel: (to-one-person) How do I perform a fetch that have a result like this: John Doe, SUM>income, SUM>amount Eva Doe, SUM>income, SUM>amount Using Swift 回答1: This is probably most easily done using Key Value Coding "collection operators" (see here) rather than a fetch. For each person : let name = person.name let totalIncome = person.valueForKeyPath(

Trouble filtering array of custom objects by an NSNumber using NSPredicate

独自空忆成欢 提交于 2021-01-29 13:28:25
问题 This should be straightforward but something is preventing me from filtering an array of custom objects by NSNumber using NSPredicate. Perhaps it has something to do with the datatype when converting from JSON but I can't figure it out. I download data from a JSON in an array of custom Objects that look like: {"hid":"47","public":"1"} The code to parse the JSON looks like: if (feedElement[@"public"] && ![feedElement[@"public"] isEqual:[NSNull null]]) { newMyObject.pub = feedElement[@"public"]

case insensitive NSPredicate with single result in CoreData

隐身守侯 提交于 2021-01-16 12:29:35
问题 Here is my current NSPredicate: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UPC==%@ OR ItemID==%@", aUPCCode,aUPCCode]; How can I make this case insensitive? And I do not want to do any partial matching. Example if they enter 123 for aUPCCode I do not want to get 123, 123a, 123b, 123c, ect. I would only want an exact match. I thought about doing this but it seems a little ridiculous: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UPC==%@ OR ItemID==%@ OR UPC==%@