簡體   English   中英

用於從coredata查詢字符串的子字符串的謂詞

[英]predicate for querying a substring of a string from coredata

在我的項目中,我在一個實體中有一組屬性。其中一個是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];

有人可以幫助編寫謂詞來獲取包含mystring的記錄。

真的很幫助我。

Tnx提前

你需要有這樣的謂詞

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

或這個

[fecthRequest setPredicate:[NSPredicate predicateWithFormat:@"bookPath contains[cd] %@", myString]];

沒有結果是由於你的%@周圍有單引號。 從文檔( 動態屬性名稱 ):

使用%@將字符串變量替換為格式字符串時,它們被引號括起來

關於謂詞我真的建議使用第一個,如果你正在尋找它的子路徑總是在原始路徑的最后部分。

關於使用謂詞,我真的建議閱讀字符串比較

希望有所幫助。

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM