NSPredicate *predicate = [NSPredicate predicateWithFormat: @"salesRepName == %@",salesName]; [request setPredicate:predicate]; This is my fetching. Is it possible to fetch the name from table and directly converting to UPPER CASE without using a string?
2 Answers
0
votes
No, that is not possible. The only way (as far as I know) to fetch computed results in a Core Data fetch request is using NSExpressionDescription with [NSExpression expressionForFunction:…],
and that does not support the uppercaseString function. So you have to convert the values
to uppercase after fetching them.
0
votes
NSExpression does support uppercase: like below:
NSExpression(forFunction: "uppercase:", arguments: [NSExpression(forKeyPath: "name")]
I've used it with NSBatchUpdateRequest successfully like below to convert all names to uppercase without fetching the records:
let batchUpdateRequest = NSBatchUpdateRequest(entityName: "Person")
batchUpdateRequest.predicate = NSPredicate(value: true)
// Convert name to uppercase
batchUpdateRequest.propertiesToUpdate = ["name": NSExpression(forFunction: "uppercase:", arguments: [NSExpression(forKeyPath: "name")])]
batchUpdateRequest.resultType = .UpdatedObjectIDsResultType
try! self.context.executeRequest(batchUpdateRequest)