NSExpression is used to represent expressions in a predicate. Comparison operations in an NSPredicate are based on two expressions, as represented by instances of the NSExpression class. Expressions are created for constant values, key paths, and so on.
Questions tagged [nsexpression]
117 questions
1
vote
1 answer
How do I aggregate (count or sum) the records in a related entity in Core Data with critieria?
I have 2 entities: Invoice and Product, that are related with a "to-many" relationship of 'products' from Invoice (Invoice.products is a list of Product entities for that invoice).
I'm trying to use an aggregate query to retrieve the # of times a…

Jeff
- 277
- 2
- 6
1
vote
0 answers
Core Data comparisons within aggregate functions
Core Data entity that has two properties on it: startDay and startDateTime. Both properties are NSDate objects. startDay has its time components set to midnight, and startDateTime designates a date with a time. Both “calendar days” within startDay…

trainface
- 120
- 1
- 2
- 9
1
vote
1 answer
Sum of a column for distinct id using core data
I want to get the sum of all values in a column for a distinct id(date in my case). My code is
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Table"];
NSPredicate *predicate = [NSPredicate…

Avinash
- 823
- 1
- 7
- 18
1
vote
1 answer
iOS core data sum data by date, month year
In iOS, I am trying to sum a core data field by day, month and year.I found some examples using NSExpression, but not this specific request.
Here is my data object:
data{
amount:NSNumber
date:NSDate
}
Looking to group the data by day, month,…

Tim Walsh
- 1,089
- 11
- 27
1
vote
1 answer
Calculate lessthan value using NSExpression?
For the following block of code:
NSString *formul=@"5 < 9";
NSExpression *e = [NSExpression expressionWithFormat:formul];
int result = [[e expressionValueWithObject:nil context:nil] intValue];
NSLog(@"formule:%d", result);
I got error:
due to…

prabu
- 71
- 11
1
vote
0 answers
Combining functions on NSExpression
I'm currently using NSExpressions to process data I am retrieving from Core Data. The entities are of type 'Transaction' and have two attributes that I am interested in: type (NSString*) and value (double). What I would like is the sum of all…

Bucky
- 21
- 2
1
vote
2 answers
Aggregate Operation on Core Data in Table View with count and grouping by date
I have a Core Data database with an entity "Event" and an attribute "eventDate" with "Date" type.
The task is showing events grouping by date and showing the number (@"count") of events date by date. For example eventDate (mm-dd-yyyy) data:
events …

BootMaker
- 1,639
- 1
- 22
- 24
0
votes
0 answers
String to Expression in Swift
I need Help
I have a simple math expression parser:
public indirect enum Expr {
case variable // could take name as associated type to support multiple vars
case const(Decimal)
case negate(Expr)
case sum([Expr])
case…

alexdark
- 21
- 3
0
votes
0 answers
iOS Core Data using CASE WHEN END equivalent for aggregate functions
--- Summary of the Question ---
I have an Entity in Core Data containing the Properties:
name: String
owned: Boolean
price: UInt16
How do I do a Fetch Request in one go (without post processing), to obtain a result collection (Dictionary, as Core…

Twelveg
- 3
- 3
0
votes
1 answer
Nested subqueries built with NSExpression crashes but not its predicate
I have some code that can recursively build nested subqueries with NSComparisonPredicate and NSExpression. Here it is when it's flat:
// Nested subquery
let entityPath = NSExpression(forKeyPath: "$s.mainUserResult.operations")
let…

lorenzo
- 1,487
- 1
- 17
- 25
0
votes
1 answer
Building a conditional expression using the Mapbox iOS SDK
I'm updating an existing iOS app that uses the Mapbox v6 SDK. The app defines a shape source using an array of point features and specifies that the points should be clustered based on a particular radius. Here's the code to do this:
let source =…

bmt22033
- 6,880
- 14
- 69
- 98
0
votes
1 answer
CoreData Fetch: Getting the objects with the maximum of one atttribute and having another attribute in common
I have a CoreData ManagedObject type Event with the properties name:Sting and date:Date.
I want to fetch all EventObject, with the name containing a filter. If more than one object with the same name matches the filter, only the object with the…

mica
- 3,898
- 4
- 34
- 62
0
votes
1 answer
Manual implementation of Standard Deviation with NSExpression
It looks like the standard deviation method for Core Data on iOS does not exists, so I'm trying to do it by hand.
I'm just starting with NSExpression so I'm struggling with this:
let numbers = [4, -2]
let numbersExpr = NSExpression(forConstantValue:…

lorenzo
- 1,487
- 1
- 17
- 25
0
votes
1 answer
SIGABRT when trying to evaluate an NSExpression or NSPredicate
I'm trying to combine NSExpression + NSPredicate to create a simple feature where the user will type something like size + 1 > 3 and it will evaluate the expression.
First, to make sure I can get NSExpression to work with a variable, I tried the…

Senseful
- 86,719
- 67
- 308
- 465
0
votes
1 answer
SwiftUI: How to combine a Double with a String and do a math calculation?
I am still totally new to Swift / SwiftUI and coding in general.
I asked this question before but it was closed because it was apparently a duplicate, but (!) this does not account for SwiftUI and I cannot get this thing to work in SwiftUI, because…

rjbcg81
- 61
- 1
- 4