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?
Fetching names from core data and converting it to upper case
318 views Asked by UrsLovinglyJamesNaddy At
2
There are 2 answers
0

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)
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 theuppercaseString
function. So you have to convert the values to uppercase after fetching them.