2011-05-15 47 views
1

我有一個自定義類MyClass,它基本上由幾個NSMutableArrays組成,沒有其他變量。我有一個實體MyEntity,它具有MyClass的ivar。當我嘗試保存實體,我得到這個堆棧轉儲:核心數據錯誤: - [myclass encodeWithCoder:]:發送到實例的無法識別的選擇器

0 CoreFoundation      0x0118ebe9 __exceptionPreprocess + 185 
1 libobjc.A.dylib      0x012e35c2 objc_exception_throw + 47 
2 CoreFoundation      0x011906fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
3 CoreFoundation      0x01100366 ___forwarding___ + 966 
4 CoreFoundation      0x010fff22 _CF_forwarding_prep_0 + 50 
5 Foundation       0x00091bf6 _encodeObject + 1076 
6 Foundation       0x0009d041 +[NSKeyedArchiver archivedDataWithRootObject:] + 206 
7 CoreData       0x00eb7255 -[NSSQLiteConnection execute] + 2677 
8 CoreData       0x00f0b646 -[NSSQLiteConnection insertRow:] + 262 
9 CoreData       0x00f082d4 -[NSSQLConnection performAdapterOperations:] + 180 
10 CoreData       0x00f07f7e -[NSSQLCore _performChangesWithAdapterOps:] + 494 
11 CoreData       0x00f06a5a -[NSSQLCore performChanges] + 410 
12 CoreData       0x00f004a8 -[NSSQLCore saveChanges:] + 216 
13 CoreData       0x00ebe739 -[NSSQLCore executeRequest:withContext:error:] + 409 
14 CoreData       0x00f6eb1b -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 3691 
15 CoreData       0x00ef6db8 -[NSManagedObjectContext save:] + 712 
16 MyProgram        0x00006d19 -[DataParser parser:didEndElement:namespaceURI:qualifiedName:] + 1665 
17 Foundation       0x00104a19 _endElementNs + 453 
18 libxml2.2.dylib      0x01620e63 xmlParseXMLDecl + 1346 
19 libxml2.2.dylib      0x0162bb6d xmlParseChunk + 3984 
20 Foundation       0x0010421a -[NSXMLParser parse] + 321 
21 MyProgram        0x0000653e -[DataParser parseXMLFileAtURL:parseError:] + 176 
22 MyProgram        0x00002912 -[MyProgramAppDelegate application:didFinishLaunchingWithOptions:] + 664 
23 UIKit        0x002cc1fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 
24 UIKit        0x002ce55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439 
25 UIKit        0x002d8db2 -[UIApplication handleEvent:withNewEvent:] + 1533 
26 UIKit        0x002d1202 -[UIApplication sendEvent:] + 71 
27 UIKit        0x002d6732 _UIApplicationHandleEvent + 7576 
28 GraphicsServices     0x01ac4a36 PurpleEventCallback + 1550 
29 CoreFoundation      0x01170064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
30 CoreFoundation      0x010d06f7 __CFRunLoopDoSource1 + 215 
31 CoreFoundation      0x010cd983 __CFRunLoopRun + 979 
32 CoreFoundation      0x010cd240 CFRunLoopRunSpecific + 208 
33 CoreFoundation      0x010cd161 CFRunLoopRunInMode + 97 
34 UIKit        0x002cdfa8 -[UIApplication _run] + 636 
35 UIKit        0x002da42e UIApplicationMain + 1160 
36 MyProgram        0x000023e6 main + 84 
37 MyProgram        0x00002389 start + 53 

是否有人在什麼都可能導致這個有什麼建議?我相信這可能與MyClass有關,但我應該如何解決這個問題?我忘了爲它寫點東西嗎?

回答

2

你是如何在實體中定義myClass ivar的?您可以使用Transformable屬性來保存非標準類型。這個想法是核心數據在幕後使用NSValueTransformer的一個實例來將屬性轉換爲NSData的實例並將其轉換爲實例。

核心數據然後將數據實例存儲到持久性存儲。

默認情況下使用NSKeyedUnarchiverFromDataTransformerName,這意味着您的自定義類必須實現NSCoding協議(與鍵控存檔支持)

檢查「非標準持久屬性」的核心數據編程指南瞭解更多細節並描述了完成相同的另一種方式。

+0

在數據模型中,我確實把myClass作爲Transformable類型。自動生成的實體文件將myClass列爲id * myClass。因此,除了在@implementation for myClass中實現NSCoding之外,我應該做什麼? – 2011-05-15 17:27:19

+1

你應該只需要實現NSCoding。 – 2011-05-15 17:51:38

+0

工作就像一個魅力。謝謝! – 2011-05-15 22:38:18

相關問題