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
2
votes
1 answer
How to loop through array of dynamic size and pass properties as arguments in variadic function?
I have a bit of an interesting question, and am not sure if what I am wanting to do is possible. If not, I imagine there is some other workaround for my issue.
I am using Mapbox (MapKit alternative) for iOS. Mapbox has style layers which let you set…

David Chopin
- 2,780
- 2
- 19
- 40
2
votes
0 answers
Searching Contacts using NSExpressions and NSPredicates
I've been able to filter a table of contacts by the contact's first name, last name, company, and notes. However, I also need to be able to search through the contact's postal addresses for the search terms. Has anyone worked with this before and…

Conner Simmons
- 63
- 1
- 9
2
votes
1 answer
Evaluating values in NSExpression
I'm using NSExpression for evaluating the following operation. But i'm getting NSInvalidArgumentException error for this. Please let me know how to evaluate the following operation.Thanks in Advance
let formula:NSString = "((y*4)⁄5)"
…

Mukesh N
- 71
- 1
- 8
2
votes
0 answers
Fetching counts of to-many Core Data relationships with NSExpression
My Core Data model has a Note entity with a to-many relationship to a Link entity, accessed through a links property on Note.
I'm trying to fetch the count of the links property for each note in Core Data. To do so, I followed the example at the…

Jack Bransfield
- 117
- 2
- 8
2
votes
2 answers
Value Expression during Core Data migration causing unusual result
I have an iOS app whose Core Data model I'm trying to migrate to a new version.
There is one new field (photoFilename) in v2 of the Core Data model, and it's value can be generated for existing entries using a v1 field (dateInSeconds) and appending…

So Over It
- 3,668
- 3
- 35
- 46
2
votes
1 answer
iOS - How to use NSExpression with one unknown parameter
I'm using NSExpression to evaluate a formula in a string.
Example -
NSString *formula = @"7+11";
NSExpression *exp = [NSExpression expressionWithFormat: formula];
NSNumber *expResult = [exp expressionValueWithObject:nil context:nil];
Everything…

user1959039
- 21
- 2
2
votes
3 answers
NSPredicateEditorRowTemplate: how to to populate right side popup
I am trying to generate an NSPredicateEditorRowTemplate that on the left side has a number of property names from an entity Foo, among which is the property bar. When the user selects 'bar', the right side should become popup which contains all…

Carelinkz
- 936
- 8
- 27
2
votes
1 answer
Core Data - Get objects filtering data using the exact elements of an array
I have 3 entities: object, object_tag and tag, and i have to get just the objects matching an array of tags by its id, but not just a tag, but that exactly matches all the tags in the array. If the array has 3 tags, return all the objects that have…

thxou
- 691
- 7
- 20
2
votes
5 answers
NSExpression 1/2
I want to calculate a string, which I'm doing by this:
NSExpression *expression = [NSExpression expressionWithFormat:calculationString];
float result = [[expression expressionValueWithObject:nil context:nil] floatValue];
NSLog(@"%f", result);
The…

sorncc
- 45
- 1
- 5
2
votes
1 answer
Chained expressions to perform calculations in Core Data
First of all: Happy new year :-)
What I am trying to do
I am trying to divide two attributes in Core Data and then calculate the average of these divisions. The attributes are specified by a key path (e.g. eur, usd, aud).
Example:
I have the…

AlexR
- 5,514
- 9
- 75
- 130
1
vote
2 answers
How do I use conditionals (e.g. ternary operator) in an NSExpression?
I'm using an NSExpression to evaluate simple strings such as:
NSExpression(format: "1 + 1").expressionValue(with: nil, context: nil) as? Int == 2
Some of my strings have more complex logic, and I'd like to use a ternary operator. I tried using the…

Senseful
- 86,719
- 67
- 308
- 465
1
vote
1 answer
How to accumulate length of managed object String property in CoreData?
Here is a Item entity In CoreData, and Item contains a property title(type is String?):
let item = Item(context: moc)
item.title = "hello world"
I want to calculate the sum of all Item.title.count:
let item_0 = Item(context: moc)
item_0.title = "a"…

hopy
- 559
- 3
- 18
1
vote
0 answers
Refresh values in a view that displays the sum of an attribute from CoreData in SwiftUI
I am working on a personal app to help me log income and calculate tax etc
I have a view that displays the totals and does a little math to calculate tax and profits etc. To get the sum values I use the following function:
func sumRevenue() ->…

Nazaroth
- 11
- 2
1
vote
1 answer
NSExpresseion, determine operating from left-associative
func postFix(_ expr: String) -> Int {
// write your code here
let nums = expr.components(separatedBy:CharacterSet.decimalDigits.inverted)
.joined()
let set = CharacterSet(charactersIn: "+*/%-")
var ch =…

Adel Kazme
- 13
- 2
1
vote
0 answers
iOS Core Data and standard deviation NSExpression crashes
I'm trying to compute a standard deviation with a Core Data fetch request
This works:
let numbers = [1, 2, 3, 4, 4, 5, 9, 11]
let statsExpression = NSExpression(forFunction:"stddev:", arguments:[NSExpression(forConstantValue: numbers)])
let…

lorenzo
- 1,487
- 1
- 17
- 25