Ios 用于从coredata查询字符串的子字符串的谓词

Ios 用于从coredata查询字符串的子字符串的谓词,ios,sqlite,core-data,nspredicate,nsfilemanager,Ios,Sqlite,Core Data,Nspredicate,Nsfilemanager,在我的项目中,我在一个实体中有一组属性。其中一个属性是path as string。我希望所有在path中将我的字符串作为子路径的记录 例如: 路径:/var/mobile/Applications/C4ECC129-36D2-4428-8BB0-6B1F4C971FC1/Library/Caches/Packages/1000 Mystring:库/缓存/包/1000 我尝试使用Like和contains,但失败了 [NSPredicate predicateWithFormat:@"book

在我的项目中,我在一个实体中有一组属性。其中一个属性是path as string。我希望所有在path中将我的字符串作为子路径的记录

例如: 路径:/var/mobile/Applications/C4ECC129-36D2-4428-8BB0-6B1F4C971FC1/Library/Caches/Packages/1000

Mystring:库/缓存/包/1000

我尝试使用Like和contains,但失败了

[NSPredicate predicateWithFormat:@"bookPath like[c] '%%%@'",Mystring];
[NSPredicate predicateWithFormat:@"bookPath Contains[cd] '%@'",Mystring];
有人可以帮助编写谓词来获取包含mystring的记录吗

真的帮了我很多忙

Tnx提前试一试:

[NSPredicate predicateWithFormat:@"%K contains %@", @"bookPath", Mystring];

你需要这样一个谓词

[fecthRequest setPredicate:[NSPredicate predicateWithFormat:@"bookPath endswith[cd] %@", myString]];
还是这个

[fecthRequest setPredicate:[NSPredicate predicateWithFormat:@"bookPath contains[cd] %@", myString]];
没有结果是由于您的
%@
周围有单引号。从文档()中:

当字符串变量被删除时,它们被引号包围 使用%替换为格式字符串@

关于谓词,我真的建议使用第一个谓词,如果要查找的子路径始终位于原始路径的最后部分

关于使用谓词,我真的建议阅读


希望能有所帮助。

我尝试过,但遇到了日志崩溃:作业似乎已崩溃:分段错误:11。如果你有什么想法,你能帮忙吗