核心数据保存例外

时间:2011-05-19 20:30:19

标签: iphone objective-c core-data

我遇到了一个非常奇怪的问题:managedObjectContext:save。它在我第一次保存上下文时没有发生,它只发生在我程序的某个时刻。你能帮助我知道它为什么会发生吗?我应该在哪里找到我的代码中的错误?感谢。

这是日志:

-[NSCFNumber UTF8String]: unrecognized selector sent to instance 0x5a64110
2011-05-19 16:02:43.235 DMC to Go[98212:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber UTF8String]: unrecognized selector sent to instance 0x5a64110'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x015d85a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0172c313 objc_exception_throw + 44
    2   CoreFoundation                      0x015da0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x01549966 ___forwarding___ + 966
    4   CoreFoundation                      0x01549522 _CF_forwarding_prep_0 + 50
    5   CoreData                            0x002f870f -[NSSQLiteConnection execute] + 1231
    6   CoreData                            0x0034aebd -[NSSQLiteConnection updateRow:] + 365
    7   CoreData                            0x00349e64 -[NSSQLConnection performAdapterOperations:] + 180
    8   CoreData                            0x00349b0e -[NSSQLCore _performChangesWithAdapterOps:] + 494
    9   CoreData                            0x003485ea -[NSSQLCore performChanges] + 410
    10  CoreData                            0x00342038 -[NSSQLCore saveChanges:] + 216
    11  CoreData                            0x00300199 -[NSSQLCore executeRequest:withContext:error:] + 409
    12  CoreData                            0x003b070b -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 3691
    13  CoreData                            0x00338948 -[NSManagedObjectContext save:] + 712
    14  DMC to Go                           0x0000313b -[dmcIpadAppDelegate saveManagedObjectChanges] + 107
    15  DMC to Go                           0x00020dc5 +[DmcIpadAppDelegate saveManagedObjectChanges] + 117
    16  DMC to Go                           0x00027883 -[DownloadFileService observeValueForKeyPath:ofObject:change:context:] + 867
    17  Foundation                          0x00fae1e4 NSKeyValueNotifyObserver + 361
    18  Foundation                          0x00fadca6 NSKeyValueDidChange + 384
    19  Foundation                          0x00f943e2 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 123
    20  DMC to Go                           0x0002c674 -[DownloadManager connectionDidFinishLoading:] + 836
    21  Foundation                          0x00fd4112 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 108
    22  Foundation                          0x00fd406b _NSURLConnectionDidFinishLoading + 133
    23  CFNetwork                           0x01dd948e _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 220
    24  CFNetwork                           0x01ea46e1 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 293
    25  CFNetwork                           0x01dcfc80 _ZN19URLConnectionClient13processEventsEv + 100
    26  CFNetwork                           0x01dcfacf _ZN17MultiplexerSource7performEv + 251
    27  CoreFoundation                      0x015b98ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    28  CoreFoundation                      0x0151788b __CFRunLoopDoSources0 + 571
    29  CoreFoundation                      0x01516d86 __CFRunLoopRun + 470
    30  CoreFoundation                      0x01516840 CFRunLoopRunSpecific + 208
    31  CoreFoundation                      0x01516761 CFRunLoopRunInMode + 97
    32  GraphicsServices                    0x0202a1c4 GSEventRunModal + 217
    33  GraphicsServices                    0x0202a289 GSEventRun + 115
    34  UIKit                               0x00838c93 UIApplicationMain + 1160
    35  DMC to Go                           0x00001f59 main + 121
    36  DMC to Go                           0x00001ed5 start + 53
    37  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'

当前语言:auto;目前的目标-c

1 个答案:

答案 0 :(得分:1)

  1. 确保您没有任何警告
  2. 在您认为在对象上设置NSString的代码中放置断点
  3. 和/或NSLog%@核心数据对象的NSString属性类,并确保它是NSString的某些变体。 (NSLog(@"%@", [obj.property class]);
  4. 正在发生的事情是您保存的NSNumber对象代替NSString。由于NSNumber没有响应UTF8String,因此您的应用程序崩溃了。