- [__ NSCFNumber length]:无法识别的选择器发送到实例0xb000000000000002

时间:2016-03-30 08:22:30

标签: ios swift core-data unrecognized-selector nscfnumber

我知道有很多相同类型的问题,但我面临着不同的问题。我在将数据保存到核心数据时遇到此错误。首先让我告诉你我的情景。我正在调用API并将其存储到数据库中。当我调用相同的API(用于下一个数据集)并且每当我收到此错误并且应用程序崩溃时我再次尝试将其推送到数据库时,没有问题,但延迟加载。即使我尝试过一些静态数据,但在第二种情况下它会崩溃。

ActivityViewController

func loadActivity() {
    CISyncManager.sharedManager().pullActivity(complition: { (activities) -> () in
       CILocalStorageManager.sharedManager().storeActivity(activities, complition: { (success, error) -> () in
           // other stuffs
        })
    })
}

func loadMoreActivity(lastId: String) {
    CISyncManager.sharedManager().pullActivity(lastId: lastId complition: { (activities) -> () in
       CILocalStorageManager.sharedManager().storeActivity(activities, complition: { (success, error) -> () in
           // other stuffs
        })
    })
}

CILocalStorageManager

func storeActivity(activities: [AnyObject], complition:((success: Bool, error: NSError?) -> ())?) {
    let queue = dispatch_queue_create("com.CILSM.activity", nil)
    for object in activities {
        dispatch_async(queue, { () -> Void in
            //design the context with `object`
            self.saveChanges()
        })
    }

    if complition != nil {
        complition!(success: true, error: nil)
    }
}

func saveChanges() {
    if !CIDataManager.sharedManager().managedObjectContext.hasChanges {
        return
    }

    CIDataManager.sharedManager().managedObjectContext.performBlock { () -> Void in
        do {
            try CIDataManager.sharedManager().managedObjectContext.save()
            print("save")
        } catch {
            print("Error : \(error)")
        }
    }
}

崩溃日志

2016-03-30 13:43:14.323 MyApp[2703:66401] -[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000002
2016-03-30 13:43:27.714 MyApp[2703:66401] CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  -[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000002 with userInfo (null)
2016-03-30 13:43:31.958 MyApp[2703:66401] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000002'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000105bfde65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000105534deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000105c0648d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000105b5390a ___forwarding___ + 970
    4   CoreFoundation                      0x0000000105b534b8 _CF_forwarding_prep_0 + 120
    5   CoreFoundation                      0x0000000105ad5dfa CFStringCompareWithOptionsAndLocale + 202
    6   Foundation                          0x00000001021a1e37 -[NSString compare:options:range:] + 29
    7   Foundation                          0x000000010222d3bd -[NSComparisonPredicateOperator performPrimitiveOperationUsingObject:andObject:] + 365
    8   Foundation                          0x00000001021fb719 -[NSPredicateOperator performOperationUsingObject:andObject:] + 286
    9   Foundation                          0x00000001021fae3c -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 313
    10  CoreData                            0x0000000104a1f931 -[NSFetchedResultsController(PrivateMethods) _objectInResults:] + 97
    11  CoreData                            0x0000000104a1fb09 -[NSFetchedResultsController(PrivateMethods) _preprocessInsertedObjects:insertsInfo:newSectionNames:] + 265
    12  CoreData                            0x0000000104a21dc6 __77-[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:]_block_invoke + 1366
    13  CoreData                            0x00000001049348a7 developerSubmittedBlockToNSManagedObjectContextPerform + 199
    14  CoreData                            0x000000010493476e -[NSManagedObjectContext performBlockAndWait:] + 222
    15  CoreData                            0x0000000104a21857 -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 119
    16  CoreFoundation                      0x0000000105bca69c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    17  CoreFoundation                      0x0000000105bca3db _CFXRegistrationPost + 427
    18  CoreFoundation                      0x0000000105bca142 ___CFXNotificationPost_block_invoke + 50
    19  CoreFoundation                      0x0000000105c0f972 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1986
    20  CoreFoundation                      0x0000000105ac5279 _CFXNotificationPost + 633
    21  Foundation                          0x0000000102199109 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
    22  CoreData                            0x000000010491a606 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 70
    23  CoreData                            0x000000010491a58a -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:deletions:updates:refreshes:deferrals:] + 1530
    24  CoreData                            0x0000000104914a0b -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 3147
    25  CoreData                            0x0000000104918444 -[NSManagedObjectContext save:] + 148
    26  MyApp                          0x0000000100f06a29 _TFC10MyApp21CILocalStorageManager11saveChangesfS0_FT_T_ + 217
    27  MyApp                          0x0000000100f06d12 _TToFC10MyApp21CILocalStorageManager11saveChangesfS0_FT_T_ + 34
    28  MyApp                          0x0000000100f037b0 _TFC10MyApp21CILocalStorageManager17storeHomeActivityfS0_FTCSo7NSArray10complitionGSqFT7successSb5errorGSqCSo7NSError__T___T_ + 384
    29  MyApp                          0x0000000100f03a34 _TToFC10MyApp21CILocalStorageManager17storeHomeActivityfS0_FTCSo7NSArray10complitionGSqFT7successSb5errorGSqCSo7NSError__T___T_ + 260
    30  MyApp                          0x0000000100eea766 _TFFFC10MyApp13CIDataManager25requestToLoadHomeActivityFS0_FT24requestToLoadNewActivitySb10completionGSqFT_T__5errorGSqFT9errorTypeOS_9ErrorType7messageGSqSS__T___T_U_FCSo7NSArrayT_U_FT_T_ + 502
    31  MyApp                          0x0000000100ea1f27 _TTRXFo__dT__XFdCb__dT__ + 39
    32  libdispatch.dylib                   0x000000010690ee5d _dispatch_call_block_and_release + 12
    33  libdispatch.dylib                   0x000000010692f49b _dispatch_client_callout + 8
    34  libdispatch.dylib                   0x00000001069172af _dispatch_main_queue_callback_4CF + 1738
    35  CoreFoundation                      0x0000000105b5dd09 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    36  CoreFoundation                      0x0000000105b1f2c9 __CFRunLoopRun + 2073
    37  CoreFoundation                      0x0000000105b1e828 CFRunLoopRunSpecific + 488
    38  GraphicsServices                    0x00000001083b6ad2 GSEventRunModal + 161
    39  UIKit                               0x00000001026a6610 UIApplicationMain + 171
    40  MyApp                          0x0000000101002f1d main + 109
    41  libdyld.dylib                       0x000000010696492d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

如果您需要任何其他信息,请告诉我们。

0 个答案:

没有答案