Questions tagged [nsexpression]

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.

117 questions
0
votes
2 answers

Swift String into formula

This may be the wrong place to ask this but I am aware of NSExpression, but it seems it can only do primitive mathematics - am I wrong about this? I am able to do something like this: @Value-2/3+9-6 ect easily, but I would like to incorporate Max's,…
Torewin
  • 887
  • 8
  • 22
0
votes
2 answers

custom NSExpression functions like sin(x)

I know how to add custom functions to NSNumber for NSExpression to work with it. But for use it i need to declarate a string like "FUNCTION(1, 'sin')". Is is any way to declarate it just like "sin(1)"?
Egor Kolyshkin
  • 117
  • 1
  • 10
0
votes
1 answer

How to catch exception when use NSExpression (swift 3)

import UIKit func calculatorFromString(colculation:String)->Double{ let mathExpression = try NSExpression(format: colculation) let mathValue = mathExpression.expressionValue(with: nil, context: nil) as? Double return…
Wind
  • 11
  • 3
0
votes
1 answer

How to get Product/Multiple array of intergers in Objective c

i having a scenario get product/multiply of array integers. were i'm to able for sum using below line of code NSNumber* sum = [intarr valueForKeyPath: @"@sum.self"]; Using NSExpression also able to get sum but not getting product/Multiply…
0
votes
1 answer

Evaluating Expressions on Server-side Swift

What is the equivalent of NSExpression to evaluate numeric expressions on the server using Swift ? Is there a library that enable that ? I'm getting this error when trying to use NSExpression on Linux: fatal error: init(format:_:) is not yet…
franck
  • 2,995
  • 3
  • 17
  • 28
0
votes
1 answer

Convert SQL Statement to Predicate or NSExpression

I am facing a problem with converting below SQL to NSExpression SELECT id,trait1,trait2,trait3,sum(trait1+trait2+trait3) as total FROM `bookings` GROUP BY id order by total desc Below is my code in this code I am only able to add the two key values…
Karamjeet Singh
  • 460
  • 1
  • 5
  • 16
0
votes
1 answer

NSExpression\NSNumber extension changed in Swift 3.0

have some extension for NSNumber: extension NSNumber { func factorialF() -> NSNumber { return tgamma(self.doubleValue + 1) } } then i use this extension in my calculation var stringFunction: String = "FUNCTION(10,'factorialF')" var…
Skie
  • 91
  • 1
  • 2
  • 13
0
votes
1 answer

How to get NSExpression for key path?

I have a table view and a search bar. I have to search for multiple keys' values and filter table accordingly. I use the following code to filter - (void)updateSearchResultsForSearchController { NSString *searchText = self.searchBr.text; …
Deepak Thakur
  • 3,453
  • 2
  • 37
  • 65
0
votes
0 answers

iOS - Complex string comparisons using NSPredicate

I need to compare strings such that certain conditions are met. The conditions are not necessarily patterns that I can match using a regex but rather "expression" conditions. For instance I would like to match a string when a number is between 2…
Avba
  • 14,822
  • 20
  • 92
  • 192
0
votes
0 answers

Evaluate value with parantheses in NSExpression

I have to evaluate the following value in NSExpression.Please help me. let calculateExpression = NSExpression(format: "6(9*9)") if let calculateConvertedValue = calculateExpression.expressionValueWithObject(nil, context: nil) as? NSNumber { …
Mukesh N
  • 71
  • 1
  • 8
0
votes
1 answer

Can I perform a single fetch request which returns independent calculations for subsets of the results?

My data model has a ClickerRecord entity with 2 attributes: date (NSDate) and numberOfBiscuits (NSNumber). Every time a new record is added, a different value for numberOfBiscuits can be entered. To calculate a daily average for the number of…
Rygen
  • 309
  • 4
  • 15
0
votes
1 answer

Single NSFetchRequest for parent and child objects

I have a list of data with parent-child hierarchy up to three levels. For example ItemA (Grandparent) ItemB1 (Parent) ItemC1 (Child) ItemC2 (Child) ItemC3 (Child) ItemB2 (Parent) ItemC4 (Child) ... All of the items are located in a single…
0
votes
1 answer

Swift - Assign a UILabel with NSExpression

How can I assign a UILabel in my app with an NSString expression? My attempt was: @IBOutlet weak var imput: UILabel! @IBOutlet weak var output: UILabel! ... ... ... @IBAction func equal(sender: AnyObject) { calculate = NSExpression(format:…
Kocsis Kristof
  • 74
  • 2
  • 10
0
votes
0 answers

Stop Rounding with NSExpression in Calculator

I have built a simple text-based calculator with swift. It takes in an expression like 88+9*3 and spits out 115. I am running in to a problem, however. When I do division (like 12/5), the answer comes out rounded (with no decimals). I understand why…
owlswipe
  • 19,159
  • 9
  • 37
  • 82
0
votes
0 answers

Swift NSExpression pow function

ill trying to code some calculator option. Please help me to create function pow(a, b) in NSExpression. need some like this: extension NSNumber { func pow() -> NSNumber { return pow(self.doubleValue, 2) } } var functionString =…
Skie
  • 91
  • 1
  • 2
  • 13