OR
및 AND
과 같은 예약어를 predicateFormat
으로 대체 할 수 있습니까? + [NSPredicate predicateWithFormat] 대체 예약어
NSString *andOr = (isAnd ? @"AND" : @"OR"); // isAnd is a BOOL variable
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"firstName == %@ %K lastName == %@",
user.firstName, andOr, user.lastName];
하지만 내가 가지고 :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Unable to parse the format string "firstName == %@ %K lastName == %@"
내가
%s
(도
%S
)를 시도하는 대신
%K
의하지만 같은 예외를 얻었다.
내 작업 솔루션은 predicateFormat
을 별도로 생성하는 것입니다. 이 별도로 predicateFormat
을 만들지 않고 할 수 있다면
NSString *predicateFormat = [NSString stringWithFormat:
@"firstName == %%@ %@ lastName == %%@", andOr];
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat,
user.firstName, user.lastName];
, 나는 궁금했다.