2012-06-11 14 views
6

Ben discount özelliğine sahip bir çekirdek veri var, Client var. Müşteriyi en küçük indirimle almak istiyorum.iOS: Bir çekirdek veride @min ve @max kullanarak

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "@min.discount"' 

sağ yapmıyorum Ne: Aşağıdaki hatayı alıyorum, ancak

[NSPredicate predicateWithFormat:@"@min.discount"]; 

:

Ben NSPredicate aşağıdaki kullanıyorum?

+0

bu (http: // geliştiricisi .apple.com/kitaplık/ios/# dokümantasyon/Kakao/Kavramsal/KeyValueCoding/Makaleler/CollectionOperators.html) – kimimaro

cevap

7

NSPredicate, boolean yüklem ifadesinin bir parçası olmadıkça (örn. "Büyüktür" gibi şeyler) bir parçası olmadıkça bunun gibi işlevlere sahip olduğunu sanmıyorum. Sen özellikle bir örnek olarak max kullanarak bazı örnekler veren this CoreData documentation okumalısınız

: [Anahtar Değer Kodlama Programlama Kılavuzu:: Koleksiyon Operatörler] Eğer aradığınız ne

There are a number of steps to follow to create and use the expression description.

First you need to create expressions (instances of NSExpression) to represent the key-path for the value you’re interested in, and to represent the function you want to apply (such as max: or min:):

NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"salary"]; 
NSExpression *maxSalaryExpression = [NSExpression expressionForFunction:@"max:" 
                arguments:[NSArray arrayWithObject:keyPathExpression]]; 

For a full list of supported functions, see expressionForFunction:arguments: .

You then create the expression description and set its name, expression, and result type.

The name is the key that will be used in the dictionary for the return value. If you want to retrieve multiple values—such as the largest and the smallest salaries in an Employee table—the name of each expression description must be unique for a given fetch request.

NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init]; 
[expressionDescription setName:@"maxSalary"]; 
[expressionDescription setExpression:maxSalaryExpression]; 
[expressionDescription setExpressionResultType:NSDecimalAttributeType]; 

Finally, you set the request’s properties to fetch just the property represented by the expression:

[request setPropertiesToFetch:[NSArray arrayWithObject:expressionDescription]]; 
İlgili konular