I have amount attribute in coredata model with string datatype. I need to find records by comparing amount. I have tried NSPredicate with following but nothing is coming and result is always empty.
NSDecimal result;
NSScanner *theScanner = [[NSScanner alloc] initWithString:@"10.00"];
[theScanner scanDecimal:&result];
[theScanner release];
[request setPredicate:[NSPredicate predicateWithFormat:@"amount > %@",[NSDecimalNumber decimalNumberWithDecimal:result]]];
NSError* error = nil;
NSArray* records = [managedObjectContext executeFetchRequest:request error:&error];
NSLog(@"%@",开发者_开发技巧records);
Please remember that i am storing amount value in string data type in coredata. following are some examples of what i am storting into data.
Examples: -12.00, +30.00 etc.
I know storing decimal values in string type is not good, but i didn't find a good way to store amount with negative or positive mark within coredata attribute. let me if there is any good way to do that.
Just use Decimal
data type for amounts (corresponds with NSDecimalNumber
class in Objective-C).
精彩评论