5
votes

I have a nasty bug and I would appreciate any guidance pointing me in the general direction of a solution. Occasionally, I get the following exception which pertains to calling initWithCoder on 3 different NSManagedObject subclasses in my core data model. If I delete the app from my device and reload it, or reset content on the simulator the exception goes away. No where in my code do I explicitly call initWithCoder on an NSManagedObject Subclass.

The bug seems to arise randomly after editing random parts of my source code. Any ideas on where to begin?

2014-01-11 15:59:22.078 Flip Evaluator and Manager[354:a0b] -[SellingCosts initWithCoder:]: unrecognized selector sent to instance 0xc2cec80
2014-01-11 15:59:22.079 Flip Evaluator and Manager[354:a0b] CoreData: error: exception during fetchRowForObjectID: -[SellingCosts initWithCoder:]: unrecognized selector sent to instance 0xc2cec80 with userInfo of (null)
2014-01-11 15:59:22.081 Flip Evaluator and Manager[354:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SellingCosts initWithCoder:]: unrecognized selector sent to instance 0xc2cec80'
*** First throw call stack:
(
    0   CoreFoundation                      0x01e9a5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01c1d8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01f37903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x01e8a90b ___forwarding___ + 1019
    4   CoreFoundation                      0x01e8a4ee _CF_forwarding_prep_0 + 14
    5   Foundation                          0x01830b2a _decodeObjectBinary + 3498
    6   Foundation                          0x0182fc15 _decodeObject + 340
    7   Foundation                          0x0182fab9 -[NSKeyedUnarchiver decodeObjectForKey:] + 181
    8   Foundation                          0x018a168d +[NSKeyedUnarchiver unarchiveObjectWithData:] + 106
    9   Foundation                          0x018202e5 -[_NSKeyedUnarchiveFromDataTransformer transformedValue:] + 47
    10  CoreData                            0x0064bd09 _prepareResultsFromResultSet + 4105
    11  CoreData                            0x00649583 newFetchedRowsForFetchPlan_MT + 1795
    12  CoreData                            0x0063448e -[NSSQLCore newRowsForFetchPlan:] + 526
    13  CoreData                            0x0065302e -[NSSQLCore fetchRowForObjectID:] + 1198
    14  CoreData                            0x00650798 -[NSSQLCore newValuesForObjectWithID:withContext:error:] + 296
    15  CoreData                            0x00650667 -[NSPersistentStoreCoordinator(_NSInternalMethods) newValuesForObjectWithID:withContext:error:] + 71
    16  CoreData                            0x0064fa3b _PFFaultHandlerLookupRow + 411
    17  CoreData                            0x0064f897 -[NSFaultHandler fulfillFault:withContext:forIndex:] + 39
    18  CoreData                            0x0064f473 _PF_FulfillDeferredFault + 259
    19  CoreData                            0x0064f2c6 _sharedIMPL_pvfk_core + 70
    20  CoreData                            0x00653cd5 -[NSManagedObject(_PFDynamicAccessorsAndPropertySupport) _genericValueForKey:withIndex:flags:] + 85
    21  CoreData                            0x0068d781 _PF_Handler_Public_GetProperty + 161
    22  CoreData                            0x0068d685 -[NSManagedObject valueForKey:] + 149
    23  Flip Evaluator and Manager          0x00030c4c -[OzCalculator sumTheValuesInSet:withAttributeKeyForValue:] + 428
    24  Flip Evaluator and Manager          0x0002f7d5 -[OzCalculator sumMoreCostsAndUpdateDataModelFor:] + 165
    25  Flip Evaluator and Manager          0x0002edc1 -[OzCalculator performAllCalculationsOnProperty:] + 817
    26  Flip Evaluator and Manager          0x00002d37 -[OzPropertyConverter createAManagedPropertyFromAnEvaluatedProperty:] + 1175
    27  Flip Evaluator and Manager          0x00041233 -[OzHaveYouPurchasedThisProperty goForwardToNextView] + 307
    28  libobjc.A.dylib                     0x01c2f874 -[NSObject performSelector:withObject:withObject:] + 77
    29  UIKit                               0x0098d0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
    30  UIKit                               0x0098d04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    31  UIKit                               0x00a850c1 -[UIControl sendAction:to:forEvent:] + 66
    32  UIKit                               0x00a85484 -[UIControl _sendActionsForEvents:withEvent:] + 577
    33  UIKit                               0x00a841fd -[UIControl touchesBegan:withEvent:] + 254
    34  UIKit                               0x009ca34b -[UIWindow _sendTouchesForEvent:] + 386
    35  UIKit                               0x009cb184 -[UIWindow sendEvent:] + 1232
    36  UIKit                               0x0099ee86 -[UIApplication sendEvent:] + 242
    37  UIKit                               0x0098918f _UIApplicationHandleEventQueue + 11421
    38  CoreFoundation                      0x01e2383f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    39  CoreFoundation                      0x01e231cb __CFRunLoopDoSources0 + 235
    40  CoreFoundation                      0x01e4029e __CFRunLoopRun + 910
    41  CoreFoundation                      0x01e3fac3 CFRunLoopRunSpecific + 467
    42  CoreFoundation                      0x01e3f8db CFRunLoopRunInMode + 123
    43  GraphicsServices                    0x02c2a9e2 GSEventRunModal + 192
    44  GraphicsServices                    0x02c2a809 GSEventRun + 104
    45  UIKit                               0x0098bd3b UIApplicationMain + 1225
    46  Flip Evaluator and Manager          0x0002e5dd main + 141
    47  libdyld.dylib                       0x030c1725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Code:

//
//  SellingCosts.h
//  Flip Evaluator and Manager
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Cost, Property, TotalCosts;

@interface SellingCosts : NSManagedObject

@property (nonatomic, strong) NSNumber * deedPrep;
@property (nonatomic, strong) NSNumber * realtyCommisionAmount;
@property (nonatomic, strong) NSNumber * realtyCommisionPercent;
@property (nonatomic, strong) NSNumber * totalCost;
@property (nonatomic, strong) NSSet *moreCosts;
@property (nonatomic, strong) Property *property;
@property (nonatomic, strong) TotalCosts *totalCosts;
@property (nonatomic, strong) NSNumber * transferTaxAmount;
@property (nonatomic, strong) NSNumber * transferTaxPercent;
@property (nonatomic, strong) NSNumber *totalIncompleteCost;
@property (nonatomic, strong) NSNumber *totalCompleteCost;

@end

Here is the method that is called before things go wrong:

-(NSInteger)sumTheValuesInSet:(NSMutableSet *)set withAttributeKeyForValue:(NSString *)attributeKey
{
    NSInteger sumToReturn = 0;
    for (id obj in set) {
        sumToReturn = sumToReturn +[[obj valueForKey:attributeKey] integerValue];
    }

    return sumToReturn;
}

The method enumerates through Cost objects in the NSSet [sellingCosts valueForKey:@"moreCosts"].

Here is the model for the Cost object//

//  Cost.h
//  Flip Evaluator and Manager
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class BuyingCosts, HoldingCosts, SellingCosts, OtherCosts, TotalCosts;

@interface Cost : NSManagedObject

@property (nonatomic, strong)    BuyingCosts *buyingCosts;
@property (nonatomic, strong)    HoldingCosts *holdingCosts;
@property (nonatomic, strong)    SellingCosts *sellingCosts;
@property (nonatomic, strong)    OtherCosts *otherCosts;
@property (nonatomic, strong) NSString * name;
@property (nonatomic, strong) TotalCosts *incompleteCosts;
@property (nonatomic, strong) TotalCosts *completedCosts;
@property (nonatomic, strong) NSNumber *complete;
@property (nonatomic, strong) id costType;
@property (nonatomic, strong) NSNumber *amount;

@end
1
post details of the model and the subclass definitions. Do you have binary or transformable attributes?Duncan Groenewald
There are no binary attributes. The class is pretty strait forward. No added methods to the subclass (implementation is posted).ChemDev
What about transformable attributes (as Duncan asked above)?Martin R
No transformables. I know this doesn't give you much to go off of but it's all I have.ChemDev
I'm seeing this as well, without transformables or binary properties in my model. I don't think this has to do with transformables.dmur

1 Answers

0
votes

Share your model as well as this appears to be a transform problem at first glance.

You should also share the code in -sumTheValuesInSet:withAttributeKeyForValue: as that seems to be the last point in your code before things go wrong.