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
0
votes
0 answers
NSExpression gives incorrect value
I have built a calculator based around NSExpression and I'm rather stumped as to why I'm receiving repeating decimals in a number of corner cases. I'm unable to cast the resulting value as an Int since the format of the NSExpression is entered by…

Hamer
- 1,354
- 1
- 21
- 34
0
votes
1 answer
terminating with uncaught exception of type NSException in Swift 5
My code works when my code makes etc: 2 + 2 But my app shut down when my code makes ex: 2+2+ .
I tried to do - catch code block and many error handling. I can't solve the problem.
let islem: String = screenTextfield.text!
let exp: NSExpression =…

Mustafa Çağrı Peker
- 15
- 6
0
votes
0 answers
Aggregate Action with CoreData
I have a CoreData "data base" and to simplify let's say that my objects have two attributes: a variable name and a variable value. I want to aggregate the content of the DB by "variable name" ("GROUP BY") and for each of the variables "names" , I…

Mansour
- 515
- 3
- 7
- 20
0
votes
0 answers
How to create a fetch to sum over the difference between attributes
In the entity Shift I have two attributes startTime and endTime, I want to take the difference and then sum over all fetched values.
let fetchRequest = NSFetchRequest(entityName: "Shift")
fetchRequest.predicate =…

Richard Legault
- 443
- 4
- 9
0
votes
0 answers
How do I extract an Int value from NSExpression?
I have a map view(mapbox) with some cluster points, the cluster is arranged and displayed based on a geojson, the logic of the cluster as if it has neighbours they will cluster when the map is zoomed out.
This works great, however, I need to…

nerway
- 1
- 5
0
votes
1 answer
How do I fix error: Binary operator '==' cannot be applied to operands of type 'NSExpression.ExpressionType' and '_'
I am going through old code from HomeKit Catalog: Creating Homes, Pairing and Controlling Accessories, and Setting Up Triggers when I ran into an expression that says
.KeyPathExpressionType
I can't tell what the
.
in
.KeyPathExpressionType
is…

daniel
- 1,446
- 3
- 29
- 65
0
votes
0 answers
Unable to create NSExpression with string from readLine()
This is my code:
print("Please enter your formula:")
let formula = readLine()
if formula == ("[0-9+-*/%]"){
let result = NSExpression(format: formula)
let result1 = result.expressionValue(with: nil, context: nil) as? Int
…

tktkt
- 1
0
votes
1 answer
Building predicate (NSExpression) to determine icon color for Mapbox SymbolStyle layer
I've recently started working with the Mapbox SDK on iOS and I've got some markers that I want to add to my map. Each marker represents an object that has several properties, among them: a type property (which backs to an enum) and a boolean…

bmt22033
- 6,880
- 14
- 69
- 98
0
votes
0 answers
Deriving an expression using NSExpression
I am stuck at a piece of code where I need to get the expression result based on the passed dictionary. For example:
expressionString = "(val1 + val2)"
How it is possible to pass these values from an dictionary or somewhere else. I searched many…

Anupam Gupta
- 623
- 1
- 7
- 18
0
votes
0 answers
Swift - use of unresolved identifier NSExpression
I tried the below code on https://iswift.org/playground, but it says use of unresolved identifier NSExpression. Please let me know if I am missing something.
var numericExpression = "4 + 3 - 2"
let expression = NSExpression(format:…

Gunjan Goel
- 1
- 2
0
votes
1 answer
String format parameters binding dictionary
Is there any built-in solution that allows to substitute strings in a manner of NSExpression does (i.e. with a binding dictionary provided)?
So instead of:
let s = String(format: "%@ %@", arguments: ["foo", "bar"]) // "foo bar"
we have:
let s =…

m8labs
- 3,671
- 2
- 30
- 32
0
votes
1 answer
Swift 4 NSExpression with Multiple Functions
So I have a string formula that let's say is:
let testValue = 10
let formula = "(max(testValue - 20,0) * 14) + testValue - max(testValue - 20,0)"
I can do simple arithmetic, multiplication, division, subtracts, ect but how would I combine the Max…

Torewin
- 887
- 8
- 22
0
votes
2 answers
Create a new NSExpression
How can i create a NSExpression with a constant value for using with the PredicateEditor.
for Example:
the leftExpression should be a string "state", the rightExpression should be as string "Germany"
i've tried:
NSExpression left = new…

Klaus Grosche
- 85
- 1
- 7
0
votes
0 answers
Swift NSExpression error handling
I was wondering if there was a way to catch the NSInvalidArgument error that is thrown when a NSExpression is invalid; such as: “4+”.
I have trying doing a guard, if let, but both seem to fail and the exception is still thrown. I know that there…

Torewin
- 887
- 8
- 22
0
votes
0 answers
Swift 3 Core Data - NSExpression combine multiple functions
I need this expression
--> sum:(abs:(amount) * -1)
and my code is:
let absExpression = NSExpression(forFunction: "abs:", arguments: [NSExpression(forKeyPath: Table.COLUMN_AMOUNT)])
let minusAbsExpression = NSExpression(format: "%@ * -1",…

Farzad Rohani
- 51
- 3