在程序的一部分的兩個陣列內我的工作,我需要計算所有的時候,每個人有每個人的其他項目的工作。假設我們有「員工」實體和「會話」實體。在每個會話中,有四個項目類型,分別是「A」,「B」,「C」,&「D」,每個項目類型都與員工建立多對多關係。檢索關係從指針
我正在做一個循環來系統地審查每個人所選擇的人合作過。首先,我將他們所有的項目類型放在一個數組中,所以它更容易循環,但是當我問最後一個嵌套的Project作爲它的Employee成員時,我得到一個「無法識別的選擇器」的錯誤。
IBOutlet NSArrayController * superList;
編輯:我忘了表示這個數組,指向控制器的arrangeObjects。
NSArray * list = [superList arrangedObjects];
int x;
for(x = 0; x < [list count]; x++){
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectAs"];
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectBs"];
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectCs"];
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectDs"];
NSArray *masterList = [[NSArray alloc] initWithObjects: projectAs, projectBs, projectCs, projectDs, nil];
int y;
for(y = 0; y < [masterList count]; y++){
int z;
for(z = 0; z < [[masterlist objectAtIndex:y] count]; z++){
//And now to make an Array of this employee's partners on the selected object, to run comparisons on.
//I also have an array of keys for each session's teams, so that's what I'm referencing here:
NSArray * thisTeam = [list objectAtIndex:y] objectAtIndex:z] valueForKey:projectKey];
這將引發異常......即 - [_ NSFaultingMutableSet objectAtIndex:]:無法識別的選擇發送到實例
出了什麼問題,去年數組創建?
我看不出有什麼理由要在這裏使用'objectAtIndex:'而不是快速枚舉:http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocFastEnumeration。 html#// apple_ref/doc/uid/TP30001163-CH18-SW1它不會解決您的問題(並且您應該只在此之後進行更改),但它會使代碼更易於閱讀。 – 2010-03-19 23:41:07
這是我在Python中知道的一個重要特性,但沒有在Kochan的Obj-C書中讀過。非常感謝分享! – DanF 2010-03-21 04:00:03