2013-10-31 36 views
0

我有一個用戶列表,每個如何篩選基於關係CoreData結果

Users.accounts ---> Accounts.measurements ---> measurement.account

我想舉例來說,從measurement.account =一個特定帳戶,以及其中measurement.type(一個屬性)是「風速」的測量「表」中抽取所有測量值。

所以我: 創建於測量 我想創建一個斷言,說類型=「風速」和帳戶= {NSAccount對象}

如何做到這一點爲獲取請求?

測量類型是容易的:

*predicate = [NSPredicate predicateWithFormat:@"measuretype = 'air speed']; 

指定的關係,我不知道:

myAccountObject *myAccount=[accountFromId:@"6785"]; 
*accountpredicate = [NSPredicate predicateWithFormat:@"account = ???",myAccount]; 
+1

您是否嘗試創建謂詞?它以前如何?它做了什麼? – Wain

+0

爲以上代碼添加了爭議。 – JeremyLaurenson

回答

0

在謂詞,%@是對象值的無功ARG取代,所以

[NSPredicate predicateWithFormat:@"account = %@",myAccount] 

可能是你在找什麼。即使對於一個常量字符串,這也是可取的,因爲它避免了嵌入引號或其他特殊字符的問題,否則必須引用該字符。所以,你的組合謂詞是:

[NSPredicate predicateWithFormat:@"measuretype = %@ AND account = %@", 
     @"air speed", myAccount] 

欲瞭解更多信息,請參閱 「謂語編程指南」中"Predicate Format String Syntax"