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
1 answer

Make a calculator that calculates multiple times

I am relatively new to swift. I made a simple text-based calculator in swift using NSExpression. I have a problem, however: this text-based calculator calculates the first expression typed into it perfectly every time (expressions from 2+4 to…
owlswipe
  • 19,159
  • 9
  • 37
  • 82
0
votes
1 answer

Why is NSExpression incorrectly evaluating this math expression?

I have the following code: NSExpression *expression; @try { expression = [NSExpression expressionWithFormat:@"20/100*200"]; NSNumber *result = [expression expressionValueWithObject:nil context:nil]; } @catch(NSException…
mattsven
  • 22,305
  • 11
  • 68
  • 104
0
votes
0 answers

NSExpression Dividing Lower Number By Higher Number

I'm trying to divide in this case 5/10 using NSExpression but it returns 0 instead of 0.5. let expn = NSExpression(format:"5/10") let answer = expn.expressionValueWithObject(nil, context: nil) as? NSNumber And Ideas?
Chad Gregory
  • 118
  • 4
  • 11
0
votes
2 answers

NSFetchRequest: Query for distinct values and count other properties values

I try to set up an NSFetchRequest for an entity Location with properties like countryand city: country | city ———————————————— Germany | Berlin USA | San Francisco USA | New York Germany | Munich Germany | Munich USA | San…
0
votes
1 answer

"random" and "random:" function for NSExpression's init(forFunction:arguments:)

Apple's document says Function random returns An NSNumber object (a random integer value) After running these two line of code: let expression = NSExpression(forFunction: "random", arguments: []) let value: AnyObject =…
fujianjin6471
  • 5,168
  • 1
  • 36
  • 32
0
votes
1 answer

How to get nil if something can't be evaluated?

I am using NSExpression to solve strings from user input. Here is the code var userInput = "5+" var solveUserInput = NSExpression(format: "\(userInput)") It will crash my program because it can't solve it, but what I want to do is to return nil if…
Epic Defeater
  • 2,107
  • 17
  • 20
0
votes
2 answers

NSExpression using sqrt: function results in NSInvalidArgumentException

I'm getting an NSInvalidArgumentException: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported function type passed to SQL store' When trying to use an NSExpression to take the square root of a nested…
timthetoolman
  • 4,613
  • 1
  • 22
  • 22
0
votes
1 answer

Adding relations during a Core Data migration – self reference

I am performing a core data migration using a mapping model. The new model adds a relationship on the Report entity called rootReport. I'd like to make this relation mandatory, rather than optional. For existing Report entities, rootReport should…
Benjohn
  • 13,228
  • 9
  • 65
  • 127
0
votes
1 answer

Doing math with NSExpression using parenthsis

I haven the NSString @"200 * (1 + (5 / 100))", when I put it into a NSExpression *expression = [NSExpression expressionWithFormat:myString]; and NSLog expression I it returns the string. When I however call [[expression expressionValueWithObject:nil…
Joseph
  • 9,171
  • 8
  • 41
  • 67
0
votes
1 answer

Conditionally sum and count data using NSExpression expressionForSubquery

I have below table, I want to fetch sum of fileSize field data which isSelectedForSync flag will be YES. Here is DigitalLibrary Table Attributes TableName: DigitalLibrary Attributes and its types: digitalLibraryID (NSNumber) fileName…
Punita
  • 1,338
  • 2
  • 13
  • 21
0
votes
1 answer

NSPredicate to check for NULL, and blank strings in Core Data

As CoreData length is not supported and CoreData translates the predicate name.length > 1 to sqlite in name > 1... While it should be length(name) > 1. We can use this one: [NSPredicate predicateWithFormat:@"NOT name MATCHES '^\s*$'"]; But…
0
votes
1 answer

Core Data: Group by and count results returns empty list

Consider the following Core Data entity: Person - personId: NSNumber, name: NSString, position: NSString Using Core Data, I'm trying to replicate the following SQL query: SELECT `position`, COUNT(*) FROM `Person` GROUP BY `position` Below is the…
krisk
  • 6,957
  • 1
  • 18
  • 30
0
votes
1 answer

Logical NSExpression evaluation

This code works: NSString* equation = @"2.5*3"; NSExpression* expresion = [NSExpression expressionWithFormat:equation, nil]; NSNumber* result = [expresion expressionValueWithObject:nil context:nil]; NSLog(@"%@", result); // 7.5 But this one…
Odrakir
  • 4,254
  • 1
  • 20
  • 52
0
votes
0 answers

Use NSExpression CAST with NSPredicate in Core Data

My problem is exactly the same as you can read in this thread: stackoverflow thread But there is a small difference. I try to explain it using the above thread's image. The CS relationship contains C type objects as it is described, but also…
Infinite Possibilities
  • 7,415
  • 13
  • 55
  • 118
0
votes
1 answer

Using NSExpression for column calculated field evaluation on CoreData. Variable substitution, formula storage

This is kind of a design question. Lets say that I have a CoreData model with 2 entities - Item and Formula. Item has 3 numeric attributes "X", "Y" and "Z", and a to-one relation to a "Formula" entity. Formula has one string attribute containing…
Motti Shneor
  • 2,095
  • 1
  • 18
  • 24