Din*_*kar 4 sqlite core-data nsfilemanager nspredicate ios
在我的项目中,我在一个实体中有一组属性.其中一个是path作为字符串.我希望所有记录都将我的字符串作为路径中的子路径.
示例: 路径:/var/mobile/Applications/C4ECC129-36D2-4428-8BB0- 6B1F4C971FC1/Library/Caches/Packages/1000
Mystring:Library/Caches/Packages/1000
我尝试使用Like和包含如下但失败了.
[NSPredicate predicateWithFormat:@"bookPath like[c] '%%%@'",Mystring];
[NSPredicate predicateWithFormat:@"bookPath Contains[cd] '%@'",Mystring];
Run Code Online (Sandbox Code Playgroud)
有人可以帮助编写谓词来获取包含mystring的记录.
真的很帮助我.
Tnx提前
Lor*_*o B 12
你需要有这样的谓词
[fecthRequest setPredicate:[NSPredicate predicateWithFormat:@"bookPath endswith[cd] %@", myString]];
Run Code Online (Sandbox Code Playgroud)
或这个
[fecthRequest setPredicate:[NSPredicate predicateWithFormat:@"bookPath contains[cd] %@", myString]];
Run Code Online (Sandbox Code Playgroud)
没有结果是由于你周围的单引号%@.从文档(动态属性名称):
使用%@将字符串变量替换为格式字符串时,它们被引号括起来
关于谓词我真的建议使用第一个,如果你正在寻找它的子路径总是在原始路径的最后部分.
关于使用谓词,我真的建议阅读字符串比较.
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
7833 次 |
| 最近记录: |