nsexpression

NSExpression\NSNumber extension changed in Swift 3.0

我与影子孤独终老i 提交于 2019-12-12 03:34:23
问题 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 expn: NSExpression = NSExpression(format: stringFunction) var result = expn.expressionValueWithObject(with: nil, context: nil) in Xcode 7.3.1 and Swift 2.2 all works but in Xcode 8 and Swift 3.0 i have some error in my extension NSNumber "No 'tgamma' candidates

How to use modulus operator with NSExpression?

爷,独闯天下 提交于 2019-12-11 11:13:54
问题 how to use modulus operator with NSExpression? If i use NSExpression *exp = [NSExpression expressionWithFormat:@"3%2"]; I'm getting an error — *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "3%2 == 1"'. Can anyone explain how to correctly use modulus operator with NSExpression? An example would be great! 回答1: NSExpression has a function feature for mathematic equations like the modulus. Here is an example of how you would

How to stop NSExpression from rounding

元气小坏坏 提交于 2019-12-11 04:12:25
问题 I've been making a calculator in Swift 3, but have run into some problems. I have been using NSExpression to calculate the users equation, but the answer is always rounded. To check that the answer was rounded, I calculated 3 / 2 . let expression = NSExpression(format: "3 / 2"); let answer: Double = expression.expressionValue(with: nil, context: nil) as! Double; Swift.print(String(answer)); The above code outputs 1.0 , instead of 1.5 . Does anyone know how to stop NSExpression from rounding?

Parsing and changing NSPredicate

喜你入骨 提交于 2019-12-07 10:18:41
问题 I have to migrate data from a previous app version to a new version. This also affects some predicates ( NSPredicate instances) that were saved by users, which means that I have to change them programmatically. Currently I try to parse the string I get with [NSPredicate predicateFormat] and change some expressions manually. For instance oldKeyPath == "something" to newKeyPath == "something" . But it feels like a hack and I'm curious if there is a better way? I read Apple's documentations

NSExpression catch invalid arguments

南笙酒味 提交于 2019-12-06 06:34:43
问题 I am using NSExpression to evaluate a mathematical string and it works great. However I want to have a way of catching an error when the input string is invalid, such as "3++2". Is there a way to go about doing this instead of the application terminating due to 'NSInvalidArgumentException'. Sorry, I am fairly new to objective-c. The code I am using now is: NSExpression *exp = [NSExpression expressionWithFormat: string]; NSNumber *result = [exp expressionValueWithObject:nil context:nil];

Parsing and changing NSPredicate

ε祈祈猫儿з 提交于 2019-12-05 17:37:26
I have to migrate data from a previous app version to a new version. This also affects some predicates ( NSPredicate instances) that were saved by users, which means that I have to change them programmatically. Currently I try to parse the string I get with [NSPredicate predicateFormat] and change some expressions manually. For instance oldKeyPath == "something" to newKeyPath == "something" . But it feels like a hack and I'm curious if there is a better way? I read Apple's documentations about programming with NSPredicate and NSExpression. There are plenty methods to compose NSPredicate

NSExpression based Core Data fetch does not retrieve current values (iOS 5, GCD)

邮差的信 提交于 2019-12-05 09:59:10
What I am trying to do I am using the code below to download data (historic foreign exchange rates) from my backend server (parse.com) to my app's Core Data store. The app checks for the latest available data stored locally and fetches only the newer data from the server. If there is no data stored locally yet, it fetches all data from the server. The way the code is set up, it fetches the data in batches of 100 objects, saves the objects in Core Data, gets the new latest date for which data is now locally stored (by using NSExpression ) and fetches the next batch until no more new objects are

NSExpression catch invalid arguments

久未见 提交于 2019-12-04 13:45:07
I am using NSExpression to evaluate a mathematical string and it works great. However I want to have a way of catching an error when the input string is invalid, such as "3++2". Is there a way to go about doing this instead of the application terminating due to 'NSInvalidArgumentException'. Sorry, I am fairly new to objective-c. The code I am using now is: NSExpression *exp = [NSExpression expressionWithFormat: string]; NSNumber *result = [exp expressionValueWithObject:nil context:nil]; answer = [result stringValue]; I think NSExpression is not the right tool for the job here. The class is

Check expression is valid or not

谁都会走 提交于 2019-12-02 17:16:08
问题 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "12+6+ == 1"' I want to validate expression is valid or not. And I am trying this using following code : let equationString = "12+6+" do { let expr = try NSExpression(format: equationString) if let result = expr.expressionValue(with: nil, context: nil) as? NSNumber { let x = result.doubleValue print(x) } else { print("failed") } } catch { print("failed") } I have used try-catch

NSFetchRequest for groupby and count combination

柔情痞子 提交于 2019-12-02 12:31:30
I'm new in Core Data, so i want to write simple fetch request to group result by some field and also a count of another field in that group. so for example i have products table i want to retrieve all grouped products by date and the count of product, the simple query in sql is like SELECT DateRegistered,Count(*) FROM Products Group By DateRegistered Your best bet is the very flexible NSFetchedResultsController . You would have a fetch request that simply fetches the Product entity sorted by the date attribute. Please note that core data attributes should start with a small letter. You would