2013-05-15 57 views
0

我是新來的核心數據如何檢查的實體是否相關或不另一個實體

我有2個實體RoutineExercise被相關的Routine.exercise和Exercise.routine。 用戶例程有一個名稱,用戶練習也有。

我試圖 也嘗試僅僅指剛Routine.exercise = Exercise但是這給了我一個警告說Comparision of distinct pointer type (NSSET and Exercise),我也試着這樣做Routine.exercise.name = @"theName",但我推它,因爲我不能得到鍛鍊的名字一樣,...

if (Routine.exercise == Exercise.routine) { 
NSLOG(@"YES"); 
} else { 
NSLOG(@"NO"); 
} 

基本上我只想知道Exercise是否與例程建立了關係。任何人都可以幫我解決這個問題嗎?

是一個多對多的關係

enter image description here

+0

是A.userB一對多的關係嗎?如果這樣可以解釋警告,因爲這些警告是作爲NSSet存儲的。 –

+0

是一個多對多的關係 –

回答

2

嘗試是這樣的:

獲取你想測試

Routine *testRoutine = ...; 
Exercise *testExercise = ...; 

檢查演習包含在對象關係中的一組對象

if ([testRoutine.exercise containsObject:testExercise]) { 
    ... 
} 
0

由於這是一個多對多的關係,所以不能使用Routine.exercise = Exercise,因爲關係是一個NSMutableSet。以下是向對象添加對象的正確方法:

NSMutableSet *rel = [routineObject mutableSetValueForKey:@"exercise"]; 
[rel addObject:exerciseObject]; 
相關問題