我從iphone開始並且面臨核心數據問題。核心數據問題
我有一個模型收集幾個實體,如員工,項目,項目類型等在啓動時,我創建了我通過核心數據框架仍然存在幾個實體。沒問題。
的問題提出時,我想顯示的基礎用戶UIToolbar
內選擇一個選項卡上的項目清單。我已經設置的參數顯示(-com.apple.CoreData.SQLDebug 1
)發佈的每一個SQL請求,什麼是真正尷尬的是,在控制檯中顯示的查詢給我的時候,通過源碼而是從核心數據訪問在我身邊的分貝我的結果,不,0行返回...
任何人都遇到了類似的問題?
這裏是用於檢索的項目的列表的代碼:
NSArray* retVal = nil;
NSError *error = nil;
NSManagedObjectContext *moc = "context retrieved";
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:moc];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
retVal = [moc executeFetchRequest:request error:&error];
NSLog(@"Project type: %@", [theProjType valueForKey:@"projectTypeName"]);
NSLog(@"Employee number: %@", [theEmployee valueForKey:@"employeeNumber"]);
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"ANY myEmployees.employeeNumber = %d AND myProjectType.projectTypeName = %d", [theEmployee valueForKey:@"employeeNumber"], [theProjType valueForKey:@"projectTypeName"]];
[request setPredicate:predicate];
retVal = [moc executeFetchRequest:request error:&error];
此代碼生成此SQL請求(在源碼分貝啓動時返回結果):
SELECT DISTINCT 0, t0.Z_PK, t0.Z_OPT, t0.ZPROJECTNUMBER, t0.ZISEDITABLE, t0.ZPROJECTNAME, t0.ZISDELETABLE, t0.ZPROJECTEND, t0.ZPROJECTID, t0.ZPROJECTSTART, t0.ZCUSTOMERORDERNR, t0.ZMYCUSTOMER, t0.ZMYCOSTCENTRE, t0.ZMYPROJECTTYPE, t0.ZMYTRAVELTIMES FROM ZPROJECT t0 JOIN Z_4MYPROJECTS t1 ON t0.Z_PK = t1.Z_10MYPROJECTS1 JOIN ZEMPLOYEE t2 ON t1.Z_4MYEMPLOYEES = t2.Z_PK JOIN ZPROJECTTYPE t3 ON t0.ZMYPROJECTTYPE = t3.Z_PK WHERE (t2.ZEMPLOYEENUMBER = ? AND t3.ZPROJECTTYPENAME = ?)
這將有助於張貼在那裏你建立NSFetchedResultsController代碼並執行讀取。 – Nimrod 2010-10-17 19:20:03
感謝Nimrod的建議,我爲我的問題添加了一些代碼。 – 2010-10-17 19:42:27