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
1
vote
2 answers

NSPredicate to get the max value of a property under a given value

I have an entity Update which has two attributes: date and amount. Suppose I have these objects in Core Data: | Date | Amount | |------------+--------| | 2020-01-01 | 100 | | 2020-01-05 | 200 | | 2020-01-10 | 300 | | 2020-01-15 | …
rayx
  • 1,329
  • 10
  • 23
1
vote
1 answer

NSExpression customization

extension String { var expression: NSExpression { return NSExpression(format: self) } } infix operator ^^ func ^^ (radix: Int, power: Int) -> Double { return Double(pow(Double(radix), Double(power))) } How can I add my infix…
Nick Shern
  • 23
  • 5
1
vote
1 answer

Check expression is valid or not

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 =…
Meet Doshi
  • 4,241
  • 10
  • 40
  • 81
1
vote
0 answers

Include Predicate Expression filter to include phonetically similar characters in search results

How to achieve filtered results that handles phonetically similar character in the search results? In attached screenshots from iOS 11 -> Settings -> Region & Languague: Searching for regions with K also includes Comoros. I'm experimenting with…
lal
  • 7,410
  • 7
  • 34
  • 45
1
vote
0 answers

NSExpression solve floating-point expressions wrong

I'm trying to solve mathematical expressions using NSPredicate and NSExpression. In case the expression is entered with floating-points at every operand the calculation gets solved correctly. Expressions, where floating points are missing for some…
regetskcob
  • 1,172
  • 1
  • 13
  • 35
1
vote
1 answer

How to stop NSExpression from rounding

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 =…
Jonty Morris
  • 797
  • 1
  • 10
  • 25
1
vote
1 answer

How to set NSFetchRequest propertiesToFetch with a custom function using NSExpression

I have a attribute "message" of type String in CoreData Entity, which stores text and sometimes including URLs . Now i need to fetch all the url's from the entity. let predicate = NSPredicate(format:"message CONTAINS[cd] %@", "http") let…
Madhu
  • 994
  • 1
  • 12
  • 33
1
vote
1 answer

How to pass arguments to a custom NSNumber function for a NSExpression in Swift?

Alright guys, I'm struggling with this: I already managed to make custom functions without arguments work like this: NSExpression(format: "function(1+1, 'myCustomFunction'").expressionValueWithObject(nil, context: nil) as! Double But I have no idea…
ThiagoAM
  • 1,432
  • 13
  • 20
1
vote
0 answers

Core data sum loses precision

I am using NSExpression to get the sum of some values from core data. The attribute type is set to int64 and the values are in hundreds or thousands of billions. The weird problem im facing is that the sum value is different from the real sum only…
Rashid
  • 762
  • 1
  • 9
  • 30
1
vote
0 answers

Use DATETIME and TIME of sqlite query in Core data

What is the predicate equivalent of SQL query DATETIME('now','+0 seconds’) > DATETIME(ZDATE,TIME(ZEND_TIME)) where ZDATE is date in format YYYY-MM-DD HH:mm:ss ZEND_TIME is date in format YYYY-MM-DD HH:mm:ss I am getting the following error when…
SandeepAggarwal
  • 1,273
  • 3
  • 14
  • 38
1
vote
0 answers

NSExpression's expressionValueWithObject:context: with non-nil parameters

Every example of expressionValueWithObject:context: that have seen so far, even in the Apple docs, always pass nil for bot parameters. Anybody could explain what these are for and a real life example? Thanks in advance!
cfischer
  • 24,452
  • 37
  • 131
  • 214
1
vote
2 answers

How to use modulus operator with NSExpression?

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…
Monis Manzoor
  • 183
  • 3
  • 14
1
vote
1 answer

Needed help for complex core data query

I have table called UserProfile as mention below I need distinct location, count for distinct location and count for status whose value is 0 at distinct location for user = user1. Status value can be between 0 t0 5(number) so output will be abc 3…
Rocker
  • 1,269
  • 7
  • 15
1
vote
1 answer

iOS Core Data Conditional Count

Actual query :- SELECT *,COUNT(case when ZISREAD = 0 then ZISREAD end) FROM ZNOTIFICATION WHERE ZTTL>1411025900 group by zkind,zaction,zname Hi, i need to convert the Count condition COUNT(case when ZISREAD = 0 then ZISREAD end)using core data…
Hiren Panchal
  • 2,963
  • 1
  • 25
  • 21
1
vote
0 answers

Creating an NSExpression that includes traversing a relationship

I am attempting to make core data fetches with an NSExpression. All fetch request will access the object 'Organisation' so that will remain constant. However I need to access relationships from this object and that is where I am having issues. So…
pls
  • 1,522
  • 2
  • 21
  • 41