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
11
votes
3 answers

Catch an exception for invalid user input in swift

I am trying this code that is a calculator. How can I handle input from the user that is not valid? //ANSWER: Bridging header to Objective-C// https://github.com/kongtomorrow/TryCatchFinally-Swift Here is the same question but in objc but I want to…
Chéyo
  • 9,107
  • 9
  • 27
  • 44
6
votes
4 answers

NSPredicateEditor & NSExpression - Can the display be different than the value for the predicate?

I have a predicate editor, which the template was generate via the following: NSArray * test = [NSArray arrayWithObjects: [NSExpression expressionForKeyPath: @"Abc"], [NSExpression…
Kyle
  • 17,317
  • 32
  • 140
  • 246
5
votes
2 answers

Correct way to catch NSInvalidArgumentException when using NSExpression

I want to validate user created expressions (like "2+2", "5+7" or more complex). I use NSExpression class to parse and calculate this expressions. This is my Playground code: import UIKit let string = "2+2" var ex:NSExpression? do { ex =…
5
votes
2 answers

NSPredicate Inside a SUBQUERY

I'm trying to write a SUBQUERY for an NSPredicate. My problem is I don't have the query on hand for the predicate portion of the SUBQUERY. Is there a way to nest an NSPredicate inside the SUBQUERY? For example this is what I have tried: let…
Nathan Hart
  • 336
  • 2
  • 13
5
votes
1 answer

How to get floating point number from the NSExpression's expressionValueWithObject:context method?

I have already implemented a custom calculator where I am using following code to evaluate the arithmetic expression something like 5+3*5-3. - (NSNumber *)evaluateArithmeticStringExpression:(NSString *)expression { NSNumber *calculatedResult =…
Goppinath
  • 10,569
  • 4
  • 22
  • 45
5
votes
3 answers

Is it possible to use a group by count in the havingPredicate for a CoreData fetch (for dupe detection)?

For reference, the problem I'm trying to solve is efficiently finding and removing duplicates in a table that could have a lot of entries. The table I am working with is called PersistedDay with a dayString object in it (it's a string. :-P). There…
stuckj
  • 977
  • 1
  • 13
  • 24
5
votes
1 answer

NSExpression respect a subquery NSPredicate

Assume that I have 2 entities, a Person and a Transaction. Person have a to-many relationship with Transaction and Transaction entity has amount and date. My goal was to have a NSFetchRequest based on the Person, but I only want to know persons who…
Rpranata
  • 2,010
  • 18
  • 24
5
votes
2 answers

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

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…
AlexR
  • 5,514
  • 9
  • 75
  • 130
4
votes
3 answers

Can I force NSExpression and expressionValue to assume Doubles instead of Ints somehow?

I'm trying to do math from a string. When I turn a string into a math problem with NSExpression, and then get the result with expressionValue, Swift assumes I want an Integer. Consider these two Playground examples: let currentCalculation = "10 /…
Beagley
  • 73
  • 1
  • 7
4
votes
2 answers

iOS FetchRequest on aggregate functions: How to include pending changes?

I've finally at least narrowed down this problem. I'm computing some aggregate functions (as in this example the sum) of expenditures. If I change some expenditures, this aggregate fetch doesn't refresh immediately but only after a while (probably…
MichiZH
  • 5,587
  • 12
  • 41
  • 81
4
votes
1 answer

Parsing and changing NSPredicate

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…
cocoafan
  • 4,884
  • 4
  • 37
  • 45
3
votes
1 answer

NSExpression catch invalid arguments

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…
Amendale
  • 317
  • 3
  • 19
3
votes
2 answers

Catching NSInvalidArgumentException from NSExpression

In my code I am evaluating strings as mathematical expressions for example: NSString *formula=@"9*7"; NSExpression *expr =[NSExpression expressionWithFormat:formula]; NSLog(@"%@", [[expr expressionValueWithObject:nil context:nil]intValue]); The…
Nathan Perry
  • 291
  • 2
  • 11
3
votes
0 answers

Fetch aggregate data from NSManagedObject using another expression as argument to sum: expression

Is it possible to use expression as argument for sum: expression? I have entity (NSManagedObject class) Drink with properties costPerDrink, numberOfDrinks and drinkingDate. I would like to get sum of total costs (numberOfDrinks multiplied by…
jki
  • 4,617
  • 1
  • 34
  • 29
2
votes
0 answers

How do I find the entire syntax / functions available in NSExpression / NSPredicate?

I tried looking for the ternary operator in the NSExpression documentation, but I couldn't find anything. I ended up finding an obscure reference in a 3rd party website to a TERNARY function, so I tried it out and sure enough, it worked. Had I not…
Senseful
  • 86,719
  • 67
  • 308
  • 465
1
2 3 4 5 6 7 8