문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top