1
Accessing the database .sqlite
via sql
normally I can use the function CAST('coluna' as decimal)
.
Via NSPredicate
using CoreData
, how do I do the same thing? I have a column like String
and I need to make a cast
for decimal
.
1
Accessing the database .sqlite
via sql
normally I can use the function CAST('coluna' as decimal)
.
Via NSPredicate
using CoreData
, how do I do the same thing? I have a column like String
and I need to make a cast
for decimal
.
0
It is possible to have CAST on an Nspredicate.
The syntax is:
CAST(<o que vai ser convertido>, 'classe destino')
Example:
NSArray *array = @[@"10.0", @"8.99"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(self, 'NSNumber') > %@", [NSNumber numberWithDouble:9.0]];
NSLog(@"%@", [array filteredArrayUsingPredicate:predicate]);
In your case, assuming your entity’s ownership in Coredata is "latitude":
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(latitude, 'NSNumber') > %@", [NSNumber numberWithDouble:9.0]];
More examples here (in English): http://funwithobjc.tumblr.com/post/1677163679/creating-an-advanced-nspredicateeditorrowtemplate
Browser other questions tagged ios objective-c sqlite swift
You are not signed in. Login or sign up in order to post.
Just to understand: if it’s a decimal, why is the column type string? And why do you need to do this cast within itself predicate?
– Paulo Rodrigues
At the moment is being treated a
latitude
andlongitude
inside the bank asString
for some other operations that will be performed later. For this reason I would have to perform this cast in "Where"– Gian
Yes, I understood that you need these columns as decimal to create your conditions. I just didn’t understand why not save these values already in a decimal column. To be honest, I don’t know anything similar to
CAST
directly onCore Data
.– Paulo Rodrigues
decimal
? What kind of data are you referring to?– fpg1503