我有以下代码:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like[c] %@", projectName];
[fetchRequest setPredicate:predicate];
[moc executeFetchRequest:request error:error]; // moc & error are defined elsewhere
当我在 projectName 为“asdf”的情况下运行此代码时,一切正常。但是,当值设置为“asdf\”(注意末尾的反斜杠)时,会出现以下异常:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The backslash is a wildcard char, and cannot appear unescaped at the end of a string.'
po request为我提供了以下信息:
po request
<NSFetchRequest: 0x101348ee0> (entity: Project; predicate: (name LIKE[c] "asdf\\"); sortDescriptors: ((null)); type: NSManagedObjectResultType; )
在我看来这是一个简单的问题,但在互联网上找不到解决方案,谁知道?