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
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.
Related
I'm debugging an iOS app (not an iOS developer) to try and solve a bug for a client as our iOS dev is away so apologies as this is probably obvious. The app is crashing with the following error message:
2019-06-03 16:34:05.292250+0100 SBD POP[75510:2099884] -[ComponentTableView tableView:heightForFooterInSection:]: unrecognized selector sent to instance 0x7f901d929200
2019-06-03 16:34:05.298376+0100 SBD POP[75510:2099884] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ComponentTableView tableView:heightForFooterInSection:]: unrecognized selector sent to instance 0x7f901d929200'
*** First throw call stack:
(
0 CoreFoundation 0x00000001126da6fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x00000001116fdac5 objc_exception_throw + 48
2 CoreFoundation 0x00000001126f8ab4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKitCore 0x000000011c8a0c3d -[UIResponder doesNotRecognizeSelector:] + 287
4 CoreFoundation 0x00000001126df1a1 ___forwarding___ + 769
5 CoreFoundation 0x00000001126e1238 _CF_forwarding_prep_0 + 120
6 SBD POP 0x000000010d1852b6 -[ComponentTableView tableView:heightForFooterInSection:] + 230
7 UIKitCore 0x000000011cab6106 -[UITableView _classicHeightForFooterInSection:] + 167
8 UIKitCore 0x000000011cabb02c -[UITableView _heightForFooterInSection:] + 34
9 UIKitCore 0x000000011cacabc4 -[UISectionRowData heightForFooterInSection:canGuess:] + 91
10 UIKitCore 0x000000011cad2277 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 653
11 UIKitCore 0x000000011ca890d7 -[UITableView _rectForFooterInSection:usingPresentationValues:] + 166
12 UIKitCore 0x000000011cab169e -[UITableView _hasHeaderFooterBelowRowAtIndexPath:] + 175
13 UIKitCore 0x000000011ca90c2f -[UITableView _shouldDrawSeparatorAtBottomOfSection:] + 126
14 UIKitCore 0x000000011caacf3d -[UITableView _setupCell:forEditing:atIndexPath:canEdit:editingStyle:shouldIndentWhileEditing:showsReorderControl:accessoryType:animated:updateSeparators:] + 1264
15 UIKitCore 0x000000011caad23f -[UITableView _setupCell:forEditing:atIndexPath:animated:updateSeparators:] + 665
16 UIKitCore 0x000000011ca9b3cb __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 2569
17 UIKitCore 0x000000011cd34a19 +[UIView(Animation) performWithoutAnimation:] + 90
18 UIKitCore 0x000000011ca9a8db -[UITableView _configureCellForDisplay:forIndexPath:] + 237
19 UIKitCore 0x000000011caad6bf -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 911
20 UIKitCore 0x000000011caadb65 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 73
21 UIKitCore 0x000000011ca75d20 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2870
22 UIKitCore 0x000000011ca95e37 -[UITableView layoutSubviews] + 165
23 UIKitCore 0x000000011cd429c1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1417
24 QuartzCore 0x000000010e051eae -[CALayer layoutSublayers] + 173
25 QuartzCore 0x000000010e056b88 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396
26 UIKitCore 0x000000011cd2d985 -[UIView(Hierarchy) layoutBelowIfNeeded] + 646
27 UIKitCore 0x000000011c1d5ec8 -[UINavigationController _layoutViewController:] + 1756
28 UIKitCore 0x000000011c1cfad8 -[UINavigationController _layoutTopViewController] + 223
29 UIKitCore 0x000000011c1cde01 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 732
30 UIKitCore 0x000000011ccfa4b6 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 418
31 UIKitCore 0x000000011ccfa779 -[UINavigationTransitionView _cleanupTransition] + 608
32 UIKitCore 0x000000011cd098ff -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 343
33 UIKitCore 0x000000011cd0516d +[UIViewAnimationState popAnimationState] + 319
34 UIKitCore 0x000000011ccfa229 -[UINavigationTransitionView transition:fromView:toView:] + 2363
35 UIKitCore 0x000000011c1d6efb -[UINavigationController _startTransition:fromViewController:toViewController:] + 3222
36 UIKitCore 0x000000011c1d73b5 -[UINavigationController _startDeferredTransitionIfNeeded:] + 896
37 UIKitCore 0x000000011c1d86a7 -[UINavigationController __viewWillLayoutSubviews] + 150
38 UIKitCore 0x000000011c1b938d -[UILayoutContainerView layoutSubviews] + 217
39 UIKitCore 0x000000011cd429c1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1417
40 QuartzCore 0x000000010e051eae -[CALayer layoutSublayers] + 173
41 QuartzCore 0x000000010e056b88 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396
42 QuartzCore 0x000000010e062ee4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 72
43 QuartzCore 0x000000010dfd23aa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 328
44 QuartzCore 0x000000010e009584 _ZN2CA11Transaction6commitEv + 608
45 UIKitCore 0x000000011c86ed8a _UIApplicationFlushRunLoopCATransactionIfTooLate + 150
46 UIKitCore 0x000000011c961f5f __handleEventQueueInternal + 6845
47 CoreFoundation 0x0000000112641be1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
48 CoreFoundation 0x0000000112641463 __CFRunLoopDoSources0 + 243
49 CoreFoundation 0x000000011263bb1f __CFRunLoopRun + 1231
50 CoreFoundation 0x000000011263b302 CFRunLoopRunSpecific + 626
51 GraphicsServices 0x0000000117f812fe GSEventRunModal + 65
52 UIKitCore 0x000000011c874ba2 UIApplicationMain + 140
53 SBD POP 0x000000010d16fc00 main + 112
54 libdyld.dylib 0x000000011606f541 start + 1
55 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I've tracked the problem down to this function (print statements are mine):
#import "ComponentTableView.h"
#import "Component.h"
#import "CoreData.h"
#import "UIPositioning.h"
#import "UIView+utils.h"
#import "UIColor+appColors.h"
#import "TotalRowView.h"
#import "NSUserDefaults+Preferences.h"
#implementation ComponentTableView
//Other code/functions here
#pragma mark - UITableViewDelegate
//Other code/functions here
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
printf("Section: %f\n", section);
switch (section) {
case 0:
{
printf("Section - Case 0\n");
if([self showSectionFooters])
{
printf("Section - Case 0 - If Statement\n");
return [super tableView:tableView heightForFooterInSection:section];
}
break;
}
case 1:
{
printf("Section - Case 1\n");
return [super tableView:tableView heightForFooterInSection:section];
break;
}
default:
{
printf("Section - Default\n");
break;
}
}
return 0;
}
ComponentTableView.h
#import "DisplayItemTableView.h"
#class ComponentTableView;
#protocol ComponentTableViewDelegate <NSObject>
- (void)onComponentTableControllerDidChangeContent:(ComponentTableView*) componentTableView;
#optional
- (void)onComponentTableViewEdit:(ComponentTableView*) componentTableView;
- (void)onDisplayItemTableVerifiedComponentsChanged:(ComponentTableView*) componentTableView;
#end
#interface ComponentTableView : DisplayItemTableView <DisplayItemViewDelegate>
#property BOOL includePreviewImage;
#property BOOL standComponentIsMandatory;
-(BOOL) outOfStock;
#property (strong, nonatomic) NSCountedSet<NSString*>* verifiedComponentSet;
#property (weak, nonatomic) id<ComponentTableViewDelegate> parentDelegate;
#property (strong, nonatomic) Component* stand;
-(CGFloat) contentHeight;
-(CGFloat) retailCost;
-(CGFloat) merchCost;
- (id) initWithComponentUIDSet:(NSCountedSet<NSString*> *) componentUIDSet;
+(CGFloat) contentHeight:(NSCountedSet*) uidset;
#end
DisplayItemTableView.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "DisplayItemView.h"
#import "TotalRowView.h"
#class DisplayItemTableView;
#interface DisplayItemTableView : UITableView<UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate>
#property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
#property (strong, nonatomic) RetailTotalView *retailTotalView;
#property (strong, nonatomic) MerchandisingTotalView *merchTotalView;
-(id) initWithHeight:(CGFloat) height;
-(id) initWithTopAndHeight:(CGFloat) top :(CGFloat) height;
+(CGFloat) displayItemHeight:(NSString*) name :(NSString*) sku :(BOOL) includePreviewImage;
+(UIColor*) separatorColor;
#end
Testing with the console prints turned on lets me know that it's the return statements:
return [super tableView:tableView heightForFooterInSection:section];
Which are causing the unregonised selector error - if I comment out case0/case1 and just leave the default the app functions but the table being generated isn't formatted correctly. Anyone have any ideas?
UITableView does not implement conformance to UITableViewDelegate, so it doesn't guarantee that it provides the method -tableView:heightForFooterInSection:. However, when ComponentTableView calls super, it's attempting to find exactly that method. You can't send a message to super when the superclass doesn't implement it.
Instead of sending to super to get a "default" value, think about what you actually want the value to be. If it's "no footer," simply return 0 from ComponentTableView's implementation. If it's "however tall Auto Layout says," return UITableViewAutomaticDimension.
One last note: many iOS apps make a point of separating the table view from its delegate and data source. You may want to consider using a view controller or other object as the delegate, instead of subclassing UITableView to implement those protocols.
RJobObject * jobObj = [RJobObject new];
RKMappingOperation *mappingOperation = [[RKMappingOperation alloc] initWithSourceObject:jobDictionary destinationObject:jobObj mapping:[RJobObject mapping]];
mappingOperation.dataSource = (id)jobObj;
[mappingOperation start];
jobDictionary structure:
NSDictionary *msg1 = #{
#"id" : #"dfcd",
#"message" : #"ndjfcdfcd"
};
NSDictionary *msg2 = #{
#"id" : #"fjvdfv",
#"message" : #"kjndcdovc"
};
NSDictionary *msg3 = #{
#"id" : #"fce",
#"message" : #"dfcdf"
};
NSArray *msgsArray = [NSArray arrayWithObjects:msg1, msg2,msg3, nil];
NSMutableDictionary * jobDictionary = [NSMutableDictionary dictionaryWithDictionary:#{#"id" : #"Sourabh pant",
#"title": #"http://www.google.com"
}];
[jobDictionary setObject:msgsArray forKey:#"messages"];
/......................................................./
RJobObject is the custom object:
#property (nonatomic) NSString * id;
#property (nonatomic) long long duration;
#property (nonatomic) NSString * title;
#property (nonatomic) NSString * image;
#property (nonatomic) NSString * secret;
#property (nonatomic) NSInteger unreadCount;
#property (nonatomic) NSArray * messages;
This creates a crash inside RRestkit, if the jobDictionary contains messages.If the messages array inside jobDictionary is empty,then the code runs fine.
So to sum up the message array is not being mapped.
Stack trace
2015-11-28 15:59:22.808 Checking Rest Kit[35951:3402596] -
[RJobObject mappingOperation:targetObjectForRepresentation:withMapping:inRelationship:]: unrecognized selector sent to instance 0x79f96270
2015-11-28 16:00:48.987 Checking Rest Kit[35951:3402596] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RJobObject mappingOperation:targetObjectForRepresentation:withMapping:inRelationship:]: unrecognized selector sent to instance 0x79f96270'
*** First throw call stack:
(
0 CoreFoundation 0x018e3a14 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x013a2e02 objc_exception_throw + 50
2 CoreFoundation 0x018ecd63 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0182a6bd ___forwarding___ + 1037
4 CoreFoundation 0x0182a28e _CF_forwarding_prep_0 + 14
5 Checking Rest Kit 0x00142f48 -[RKMappingOperation destinationObjectForMappingRepresentation:parentRepresentation:withMapping:inRelationship:] + 1704
6 Checking Rest Kit 0x00149885 __64-[RKMappingOperation mapOneToManyRelationshipWithValue:mapping:]_block_invoke + 149
7 CoreFoundation 0x018152e9 __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 73
8 CoreFoundation 0x01815182 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 162
9 CoreFoundation 0x017ff835 -[NSArray enumerateObjectsUsingBlock:] + 53
10 Checking Rest Kit 0x0014920b -[RKMappingOperation mapOneToManyRelationshipWithValue:mapping:] + 2763
11 Checking Rest Kit 0x0014b4fb -[RKMappingOperation applyRelationshipMappings] + 6283
12 Checking Rest Kit 0x0014d7db -[RKMappingOperation main] + 4075
13 Checking Rest Kit 0x0014c7dd -[RKMappingOperation start] + 45
14 Checking Rest Kit 0x000ab866 -[ViewController jobObjectFromJobDictionary:] + 310
15 Checking Rest Kit 0x000ab6d5 -[ViewController fetchJobFromDbForId:] + 85
16 Checking Rest Kit 0x000ab566 -[ViewController viewDidLoad] + 918
17 UIKit 0x01e3b2ae -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
18 UIKit 0x01e3fdce -[UIViewController loadViewIfRequired] + 1384
19 UIKit 0x01e401ed -[UIViewController view] + 35
20 UIKit 0x01cedf94 -[UIWindow addRootViewControllerViewIfPossible] + 69
21 UIKit 0x01cee6b1 -[UIWindow _setHidden:forced:] + 304
22 UIKit 0x01ceea67 -[UIWindow _orderFrontWithoutMakingKey] + 49
23 UIKit 0x01d02118 -[UIWindow makeKeyAndVisible] + 80
24 UIKit 0x01c6a6e7 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4190
25 UIKit 0x01c71cd6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1989
26 UIKit 0x01c96ee5 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3218 + 68
27 UIKit 0x01c6e966 -[UIApplication workspaceDidEndTransaction:] + 163
28 FrontBoardServices 0x04c4dc76 __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
29 FrontBoardServices 0x04c4d74d __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
30 FrontBoardServices 0x04c6b173 -[FBSSerialQueue _performNext] + 184
31 FrontBoardServices 0x04c6b5aa -[FBSSerialQueue _performNextFromRunLoopSource] + 52
32 FrontBoardServices 0x04c6a8a6 FBSSerialQueueRunLoopSourceHandler + 33
33 CoreFoundation 0x017fd6ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
34 CoreFoundation 0x017f338b __CFRunLoopDoSources0 + 523
35 CoreFoundation 0x017f27a8 __CFRunLoopRun + 1032
36 CoreFoundation 0x017f20e6 CFRunLoopRunSpecific + 470
37 CoreFoundation 0x017f1efb CFRunLoopRunInMode + 123
38 UIKit 0x01c6e206 -[UIApplication _run] + 540
39 UIKit 0x01c73bfa UIApplicationMain + 160
40 Checking Rest Kit 0x000af02a main + 138
41 libdyld.dylib 0x03911a21 start + 1
42 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
In Rconnection.m
- (id)destinationObjectForMappingRepresentation:(id)representation parentRepresentation:(id)parentRepresentation withMapping:(RKMapping *)mapping inRelationship:(RKRelationshipMapping *)relationshipMapping {
/* Some Code */
............
if (destinationObject == nil)
{
NSDictionary *dictionaryRepresentation = [representation isKindOfClass:[NSDictionary class]] ? representation : #{ [NSNull null] : representation };
RKMappingMetadata *parentMetadata = [RKMappingMetadata new];
parentMetadata.parentObject = self.destinationObject ?: [NSNull null];
NSArray *metadata = RKInsertInMetadataList(self.metadataList, parentMetadata, nil);
RKMappingSourceObject *sourceObject = [[RKMappingSourceObject alloc] initWithObject:dictionaryRepresentation parentObject:parentRepresentation rootObject:self.rootSourceObject metadata:metadata];
// Crashing Breakpoint below:
destinationObject = [dataSource mappingOperation:self targetObjectForRepresentation:(NSDictionary *)sourceObject withMapping:concreteMapping inRelationship:relationshipMapping];
}
.......
/* Some code */
}
#import <Foundation/Foundation.h>
#import <RestKit/RestKit.h>
#interface RJobObject : NSObject
#property (nonatomic) NSString * id;
#property (nonatomic) long long duration;
#property (nonatomic) NSString * title;
#property (nonatomic) NSString * image;
#property (nonatomic) NSString * secret;
#property (nonatomic) NSInteger unreadCount;
#property (nonatomic) NSArray * messages;
+(RKObjectMapping *)mapping;
#end
This line is incorrect:
mappingOperation.dataSource = (id)jobObj;
because you are giving the operation a plain data model object as a data source (and telling the compiler to like it by casting to id).
When the operation runs it needs some new instances to be created so it can map the content from the JSON dict into them, this is a job the data source is supposed to do. When the operation asks the data source you get a crash because the object you provided as the data source, jobObj, doesn't understand the request.
You need to create and set an appropriate data source that can handle this requirement.
I am trying to remove every instance of an RLMObject subclass and whenever I call [Realm defaultRealm] my app crashes. Here is what I keep getting in the console. I am using cocoapods, version 0.93.2
*** Terminating app due to uncaught exception 'RLMException', reason: 'Can't persist property 'Id' with incompatible type. Add to ignoredPropertyNames: method to ignore.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106b15c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001067aebb7 objc_exception_throw + 45
2 business_sect 0x000000010206251b -[RLMProperty initWithName:indexed:property:] + 571
3 business_sect 0x00000001020511c1 +[RLMObjectSchema propertiesForClass:isSwift:] + 1457
4 business_sect 0x000000010204fa5c +[RLMObjectSchema schemaForObjectClass:] + 812
5 business_sect 0x00000001020c4d06 +[RLMSchema initialize] + 1862
6 libobjc.A.dylib 0x00000001067af4d6 _class_initialize + 648
7 libobjc.A.dylib 0x00000001067b86e1 lookUpImpOrForward + 351
8 libobjc.A.dylib 0x00000001067c50d3 objc_msgSend + 211
9 business_sect 0x00000001020aa34d +[RLMRealm realmWithPath:key:readOnly:inMemory:dynamic:schema:error:] + 4765
10 business_sect 0x00000001020a8d78 +[RLMRealm realmWithPath:readOnly:error:] + 152
11 business_sect 0x00000001020a8bdf +[RLMRealm defaultRealm] + 111
12 business_sect 0x0000000101f386ff __40-[CGCUserManager signInUser:completion:]_block_invoke + 879
13 business_sect 0x0000000101fd39d8 __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke46 + 40
14 libdispatch.dylib 0x0000000107095186 _dispatch_call_block_and_release + 12
15 libdispatch.dylib 0x00000001070b4614 _dispatch_client_callout + 8
16 libdispatch.dylib 0x000000010709ca1c _dispatch_main_queue_callback_4CF + 1664
17 CoreFoundation 0x0000000106a7d1f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18 CoreFoundation 0x0000000106a3edcb __CFRunLoopRun + 2043
19 CoreFoundation 0x0000000106a3e366 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x0000000107d63a3e GSEventRunModal + 161
21 UIKit 0x0000000104e6d8c0 UIApplicationMain + 1282
22 business_sect 0x0000000101f6927f main + 111
23 libdyld.dylib 0x00000001070e8145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
EDIT: I am also testing on the iphone6 simulator
Here is the RLMObject subclass:
#import "RLMObject.h"
#interface CGCUser : RLMObject
#property NSString *EmailAddress;
#property BOOL IsActive;
#end
And a second object
#interface CGCCardInfo : RLMObject
#property NSInteger *Id;
#property NSString *nickName;
#property NSString *token;
#property NSString *displayNumber;
#property BOOL *isDefault;
#property NSString *cardType;
#end
RLM_ARRAY_TYPE(CGCCardInfo)
The issue there is the line #property BOOL *isDefault;
If you change that to #property BOOL isDefault; it should do exactly what you want!
The same happened to me.
#property NSInteger *Id is the problematic field over here. You use a pointer to NSInteger instead of NSInteger itself.
The solution is to replace it with a direct reference: #property NSInteger Id
I have followed all the steps mentioned in Facebook IOS SDK Docs.
My ViewController.h file is as below
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#interface ViewController : UIViewController <FBLoginViewDelegate>
#end
My ViewController.m file is as below
#import "AppDelegate.h"
#import "ViewController.h"
#import "pageLike.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet FBLoginView *fbloginbtn;
#property (weak, nonatomic) IBOutlet UILabel *name;
#property (weak, nonatomic) IBOutlet FBProfilePictureView *fbimage;
#property (weak, nonatomic) IBOutlet UILabel *status;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.fbloginbtn.readPermissions = #[#"public_profile",#"email",#"user_friends"];
self.fbloginbtn.publishPermissions = #[#"publish_actions"];
self.fbloginbtn.delegate =self;
// Do any additional setup after loading the view, typically from a nib.
if(FBSessionStateOpen){
pageLike *pg=[self.storyboard instantiateViewControllerWithIdentifier:#"pageLike"];
[self.navigationController pushViewController:pg animated:YES];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
self.fbimage.profileID=user.id;
self.name.text = user.name;
}
#end
And Error trace is as under
2014-12-31 17:59:09.830 fbconnect[2274:96019] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: __view_impression_identifier__)'
*** First throw call stack:
(
0 CoreFoundation 0x0110a946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x009f2a97 objc_exception_throw + 44
2 CoreFoundation 0x00ffdbbc -[__NSDictionaryM setObject:forKey:] + 940
3 CoreFoundation 0x0107a210 -[NSMutableDictionary setObject:forKeyedSubscript:] + 48
4 fbconnect 0x0007c1b8 -[FBViewImpressionTracker logImpressionWithView:identifier:parameters:] + 76
5 fbconnect 0x000a8428 -[FBLikeControl drawRect:] + 183
6 UIKit 0x0175c95c -[UIView(CALayerDelegate) drawLayer:inContext:] + 519
7 QuartzCore 0x04ef9d61 -[CALayer drawInContext:] + 118
8 QuartzCore 0x04ef9c97 _ZL16backing_callbackP9CGContextPv + 96
9 QuartzCore 0x04dde4fe CABackingStoreUpdate_ + 2788
10 QuartzCore 0x04ef9c2f ___ZN2CA5Layer8display_Ev_block_invoke + 93
11 QuartzCore 0x04f2f416 x_blame_allocations + 15
12 QuartzCore 0x04ef9a95 _ZN2CA5Layer8display_Ev + 1591
13 QuartzCore 0x04ef9ce6 -[CALayer _display] + 33
14 QuartzCore 0x04ef9456 _ZN2CA5Layer7displayEv + 142
15 QuartzCore 0x04ef9cc0 -[CALayer display] + 33
16 QuartzCore 0x04eedef6 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 322
17 QuartzCore 0x04eedf7c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 38
18 QuartzCore 0x04e4c3c6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284
19 QuartzCore 0x04e4d78c _ZN2CA11Transaction6commitEv + 392
20 QuartzCore 0x04e4de58 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21 CoreFoundation 0x0102d9de __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22 CoreFoundation 0x0102d920 __CFRunLoopDoObservers + 400
23 CoreFoundation 0x0102335a __CFRunLoopRun + 1226
24 CoreFoundation 0x01022bcb CFRunLoopRunSpecific + 443
25 CoreFoundation 0x010229fb CFRunLoopRunInMode + 123
26 GraphicsServices 0x028da24f GSEventRunModal + 192
27 GraphicsServices 0x028da08c GSEventRun + 104
28 UIKit 0x016d18b6 UIApplicationMain + 1526
29 fbconnect 0x00079a0d main + 141
30 libdyld.dylib 0x060dcac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I have created another view controller named pageLike where i need to actually navigate once user is logged in
Check the pageLike controller and remove all the fb login view controller as they might be creating issues .
I am receiving the following response from my REST Server.
{
id: 1,
model_id: 1,
plant_id: 1,
users: [
2,
9
]
}
To which I am trying to map the following model:
#property (nonatomic, retain) Model *model;
#property (nonatomic, retain) Plant *plant;
#property (nonatomic, retain) NSSet *expertUsers;
and "expertUsers" is a set of objects, based of a class called "User".
Now, I am trying to follow the same approach I have used in the past to connect users to objects, without having the full object. I have been using the following solution, and it works great for single objects.
[pictureMapping addConnectionForRelationship:#"lastModifiedBy" connectedBy:#{ #"lastModifiedByID": #"identifier" }];
However, how can I replicate the same thing, but this time with an array of IDs?
I would need something like this:
[modelExperts addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"users" toKeyPath:#"expertUsers" withMapping:userMapping **addConnectionForRelationship:#"lastModifiedBy" connectedBy:#{ #"lastModifiedByID": #"identifier" }**]];
EDIT #1:
Here is my current Core Data model:
#interface Cell : NSManagedObject
#property (nonatomic, retain) NSNumber *identifier;
#property (nonatomic, retain) NSSet *managers; // To Many Users
#end
#interface User : NSManagedObject
#property (nonatomic, retain) NSNumber *identifier;
#end
RKEntityMapping *cellMapping = [RKEntityMapping mappingForEntityForName:#"Cell" inManagedObjectStore:managedObjectStore];
cellMapping.identificationAttributes = #[#"identifier"];
NSEntityDescription *cellManagersEntityDescription = [NSEntityDescription entityForName:#"Cell" inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
NSRelationshipDescription *userManagersRelationshipDescription = [cellManagersEntityDescription relationshipsByName][#"managers"]; // To many relationship for the `User` entity
RKConnectionDescription *cellManagersConnection = [[RKConnectionDescription alloc] initWithRelationship:userManagersRelationshipDescription attributes:#{ #"managers": #"identifier" }];
[cellMapping addConnection:cellManagersConnection];
Here is my Rest JSON answer for Cell:
{
id: 1,
managersIDs: [
2
],}
However, I keep getting the following:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot connect relationship: invalid attributes given for source entity 'Cell': managers'
*** First throw call stack:
(
0 CoreFoundation 0x03c646f4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02df38b6 objc_exception_throw + 44
2 CoreFoundation 0x03c64558 +[NSException raise:format:arguments:] + 136
3 Foundation 0x029d45ee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 Poka 0x001db61f -[RKConnectionDescription initWithRelationship:attributes:] + 1279
5 Poka 0x0000bdf3 -[APIConnector setupMapping] + 12451
6 Poka 0x000089ef -[APIConnector init] + 159
7 Poka 0x001863da -[IJContext createClassInstanceFromRegistration:withProperties:] + 186
8 Poka 0x00184f12 -[IJContext instantiateClass:withProperties:] + 594
9 Poka 0x00186de0 +[NSObject(Injective) injectiveInstantiate] + 96
10 Poka 0x00008275 -[PokaAppDelegate application:didFinishLaunchingWithOptions:] + 309
11 UIKit 0x01b65525 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
12 UIKit 0x01b65d65 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
13 UIKit 0x01b6a578 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
14 UIKit 0x01b7e57c -[UIApplication handleEvent:withNewEvent:] + 3447
15 UIKit 0x01b7eae9 -[UIApplication sendEvent:] + 85
16 UIKit 0x01b6c1f5 _UIApplicationHandleEvent + 736
17 GraphicsServices 0x048bc33b _PurpleEventCallback + 776
18 GraphicsServices 0x048bbe46 PurpleEventCallback + 46
19 CoreFoundation 0x03bdfe95 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
20 CoreFoundation 0x03bdfbcb __CFRunLoopDoSource1 + 523
21 CoreFoundation 0x03c0a8ac __CFRunLoopRun + 2156
22 CoreFoundation 0x03c09bf3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x03c09a0b CFRunLoopRunInMode + 123
24 UIKit 0x01b69cad -[UIApplication _run] + 840
25 UIKit 0x01b6bf0b UIApplicationMain + 1225
26 Poka 0x0000810d main + 141
27 libdyld.dylib 0x032db725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The class you're looking for is RKConnectionDescription. The code would look something like:
NSEntityDescription *pictureEntity = [NSEntityDescription entityForName:#"Picture" inManagedObjectContext:managedObjectContext];
NSRelationshipDescription *expertUsers = [pictureEntity relationshipsByName][#"expertUsers"]; // To many relationship for the `User` entity
RKConnectionDescription *connection = [[RKConnectionDescription alloc] initWithRelationship:expertUsers attributes:#{ #"users": #"userID" }];
Assuming that your entities are Picture and User and that the User entity has an identity attribute named userID and the Picture entity has an NSArray or NSSet attribute that is named users and contains the identities mapped from users in the JSON.
Then you can add the connection to your pictureMapping.
In your new code, this line is wrong:
RKConnectionDescription *cellManagersConnection = [[RKConnectionDescription alloc] initWithRelationship:userManagersRelationshipDescription attributes:#{ #"managers": #"identifier" }];
Because it is using the managers attribute which holds the entity instances. It should be linking to an attribute that you don't have which holds the identities of the manager entity instances that you want to link to. So:
Add an attribute managerIds
Add a mapping to fill managerIds with the ids from the JSON
Update cellManagersConnection to reference managers