My app is essentially a collection of cards, each with various messages/information on it. One swipes to go through these cards, generally swiping right. I am currently getting this sig abrt error:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
It also prints, this:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[filterPageViewController askForPushNotifications]: unrecognized selector sent to instance 0x7f8b6d0acd80'
*** First throw call stack:
(
0 CoreFoundation 0x000000010fa92d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010f506deb objc_exception_throw + 48
2 CoreFoundation 0x000000010fa9bd3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f9e1cfa ___forwarding___ + 970
4 CoreFoundation 0x000000010f9e18a8 _CF_forwarding_prep_0 + 120
5 Lettuce 0x000000010a2780a6 -[DraggableViewBackground cardSwipedRight:] + 2470
6 Lettuce 0x000000010a2d0ad5 -[DraggableView rightAction] + 453
7 Lettuce 0x000000010a2d02ed -[DraggableView afterSwipeAction] + 77
8 Lettuce 0x000000010a2cfe22 -[DraggableView beingDragged:] + 1922
9 UIKit 0x000000010d9c7b28 _UIGestureRecognizerSendTargetActions + 153
10 UIKit 0x000000010d9c419a _UIGestureRecognizerSendActions + 162
11 UIKit 0x000000010d9c2197 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843
12 UIKit 0x000000010d9ca655 ___UIGestureRecognizerUpdate_block_invoke898 + 79
13 UIKit 0x000000010d9ca4f3 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342
14 UIKit 0x000000010d9b7e75 _UIGestureRecognizerUpdate + 2634
15 UIKit 0x000000010d54448e -[UIWindow _sendGesturesForEvent:] + 1137
16 UIKit 0x000000010d5456c4 -[UIWindow sendEvent:] + 849
17 UIKit 0x000000010d4f0dc6 -[UIApplication sendEvent:] + 263
18 UIKit 0x000000010d4ca553 _UIApplicationHandleEventQueue + 6660
19 CoreFoundation 0x000000010f9b8301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x000000010f9ae22c __CFRunLoopDoSources0 + 556
21 CoreFoundation 0x000000010f9ad6e3 __CFRunLoopRun + 867
22 CoreFoundation 0x000000010f9ad0f8 CFRunLoopRunSpecific + 488
23 GraphicsServices 0x00000001107e2ad2 GSEventRunModal + 161
24 UIKit 0x000000010d4cff09 UIApplicationMain + 171
25 Lettuce 0x000000010a2c3f0f main + 111
26 libdyld.dylib 0x000000011012492d start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
After some investigating, I have found the problematic code. It is a line within my cardSwipedRight method that is in my draggableviewbackground class (this class functions as a deck, to hold all of the cards) :
[((settingsTableViewController *)([obj.superNavController.viewControllers[obj.profileNum] viewControllers][0])) askForPushNotifications];
This line of code is within an if statement that checks whether this is a "sign me up for notifications card". What I'm confused by, is why xcode associated filterPageView with askForPushNotifications. Not only does filterPageView not have a askForPushNotifications method, but I don't swipe right on filterPageView nor have I viewed it by the time my app crashes.
One receives an unrecognized selector exception when the object to which the selector is sent does not implement/respond to the sent selector. In simple words, if a class A does not implement a method and someone try to call that method on an object of class A, runtime throws an unrecognized selector exception.
When we are not sure whether an object will respond to a selector, we should have a safety check to see if an object responds to intended selector.
For eg.
if ([*obj* respondsToSelector:#selector(*selector*)])
{
[*obj* performSelector:*selector*];
}
unrecognized selector sent to instance comes up when you try to call a method on an object but that method doesn't exist (The corrrect terminology is that you have tried to send a message called "askForPushNotifications" but the settingsTableViewController does not understand it as it(askForPushNotifications) doesn't exit . I am sure you may not have that method in your settingsTableViewController. Please check and let me know if that helped you.
Also, please check with respondsToSelector if the object actually responds to the method askForPushNotifications. It may be the case that
((settingsTableViewController
*)([obj.superNavController.viewControllers[obj.profileNum] viewControllers][0]))
may not be of type SettingsTableViewController. Please check
if [(((settingsTableViewController *)([obj.superNavController.viewControllers[obj.profileNum] viewControllers][0])) respondsToSelector:#selector(askForPushNotifications)]
{
[((settingsTableViewController *)([obj.superNavController.viewControllers[obj.profileNum] viewControllers][0])) askForPushNotifications];
}
Related
We have a react-native app that we develop as a standalone app and then we have a pod that exports the app with a native entry point. Part of our app uses react-native-awesome-card-io which works fine when we run the the app as a standalone piece (metro bundler). We use cocoa pods to manage the dependencies that react-native link usually does for us. We were using react-native: 57.8 but had to upgrade to 59.0 in order to be able to integrate our plugin into android apps without having to add filtering for 32/64 bit. Anyways we have an example app that just has a button and when the button is pressed, the action takes the view controller we created and presentModalViewController is triggered. The issue came up after we upgraded react-native, when we call the scanCard function on press in our react-native js, The following error comes up
It worked fine previously and it works if we run the app as a standalone react-native app but when we integrate it, the issue comes up. Here is how we instantiate the react-native plugin.
NOTE: it fails for both our objective-c and swift example consumer apps. I haven't found anything online.
How we load our viewcontroller in our sample app
- (IBAction)launchPaciolanSDKAction:(UIButton *)sender {
printf("Launching PaciolanSDK ...");
UIViewController *viewController = nil;
viewController = [[PaciolanSDKViewController alloc] initWithString::""];
[self presentModalViewController:viewController animated:YES];
}
Error:
Exception 'Please add -ObjC to 'Other Linker Flags' in your project settings. (+[NSObject testForObjCLinkerFlag]: unrecognized selector sent to class 0x1dbbd7eb0)' was thrown while invoking scanCard on target CardIOModule with params (
{
hideCardIOLogo = 1;
requireCardholderName = 1;
suppressManualEntry = 1;
usePaypalActionbarIcon = 0;
},
3544,
3545
)
callstack: (
0 CoreFoundation 0x00000001a1cf5ebc <redacted> + 252
1 libobjc.A.dylib 0x00000001a0ec5a50 objc_exception_throw + 56
2 CoreFoundation 0x00000001a1bfc484 <redacted> + 0
3 RNAwesomeCardIO 0x000000010385bf6c -[CardIOPaymentViewController initWithPaymentDelegate:scanningEnabled:] + 660
4 RNAwesomeCardIO 0x00000001038598bc -[RCTCardIOModule scanCard:resolver:rejecter:] + 236
5 CoreFoundation 0x00000001a1cfd610 <redacted> + 144
6 CoreFoundation 0x00000001a1bdb340 <redacted> + 292
7 CoreFoundation 0x00000001a1bdbf24 <redacted> + 60
8 React 0x0000000103ec3d10 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2064
9 React 0x0000000103ecfe2c _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 664
10 React 0x0000000103ecf99c _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 144
11 React 0x0000000103ecf900 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 28
12 libdispatch.dylib 0x000000010494f824 _dispatch_call_block_and_release + 24
13 libdispatch.dylib 0x0000000104950dc8 _dispatch_client_callout + 16
14 libdispatch.dylib 0x000000010495ea78 _dispatch_main_queue_callback_4CF + 1360
15 CoreFoundation 0x00000001a1c85ce4 <redacted> + 12
16 CoreFoundation 0x00000001a1c80bac <redacted> + 1964
17 CoreFoundation 0x00000001a1c800e0 CFRunLoopRunSpecific + 436
18 GraphicsServices 0x00000001a3ef9584 GSEventRunModal + 100
19 UIKitCore 0x00000001cefe0c00 UIApplicationMain + 212
20 sample 0x0000000102f0e1fc main + 124
21 libdyld.dylib 0x00000001a173ebb4 <redacted> + 4
)
Check out your parameters and headers that you are sending to api.This error mostly occur when we send wrong parameters.
This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
I have an XCode Project which I was developing in objective C but now with Swift I have a few classes saved as .swift files. When I am referencing these as custom classes in the Interface Builder, they don't work and I get an error that the class doesn't exist.
What am I missing in terms of bridging the gap between the two? I have the header file to make the objective C available to Swift but not sure about the other way around
Thanks
2014-07-08 20:18:07.463 FoodForTeeth[22030:70b] Unknown class SecondViewController in Interface Builder file.
2014-07-08 20:18:07.496 FoodForTeeth[22030:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x8c85390> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key date.'
*** First throw call stack:
(
0 CoreFoundation 0x01acf5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018528b6 objc_exception_throw + 44
2 CoreFoundation 0x01b5f6a1 -[NSException raise] + 17
3 Foundation 0x01513c2e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x0147ff3b _NSSetUsingKeyValueSetter + 88
5 Foundation 0x0147f493 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x014e194a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x00866cd5 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x018647d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x01acab6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x0086582e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x006d7c95 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
12 UIKit 0x006d843d -[UIViewController loadView] + 302
13 UIKit 0x006d873e -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x006d8c44 -[UIViewController view] + 35
15 UIKit 0x006f2a72 -[UINavigationController _startCustomTransition:] + 778
16 UIKit 0x006ff757 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
17 UIKit 0x00700349 -[UINavigationController __viewWillLayoutSubviews] + 57
18 UIKit 0x0083939d -[UILayoutContainerView layoutSubviews] + 213
19 UIKit 0x0062fdd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
20 libobjc.A.dylib 0x0186481f -[NSObject performSelector:withObject:] + 70
21 QuartzCore 0x045ab72a -[CALayer layoutSublayers] + 148
22 QuartzCore 0x0459f514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
23 QuartzCore 0x0459f380 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
24 QuartzCore 0x04507156 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
25 QuartzCore 0x045084e1 _ZN2CA11Transaction6commitEv + 393
26 QuartzCore 0x04508bb4 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
27 CoreFoundation 0x01a9753e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
28 CoreFoundation 0x01a9748f __CFRunLoopDoObservers + 399
29 CoreFoundation 0x01a753b4 __CFRunLoopRun + 1076
30 CoreFoundation 0x01a74b33 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x01a7494b CFRunLoopRunInMode + 123
32 GraphicsServices 0x02ebc9d7 GSEventRunModal + 192
33 GraphicsServices 0x02ebc7fe GSEventRun + 104
34 UIKit 0x005c594b UIApplicationMain + 1225
35 FoodForTeeth 0x0001c42d main + 141
36 libdyld.dylib 0x02b5e701 start + 1
37 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
SecondViewController.swift
import UIkit
import CoreData
#objc(SecondViewController) class SecondViewController: UIViewController, UITextFieldDelegate {
#IBOutlet var txtTask: UITextField!
#IBOutlet var txtDesc: UITextField!
#IBOutlet var date: UIDatePicker!
#IBOutlet var dateDisplayLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
configureDatePicker()
}
func configureDatePicker() {
date.addTarget(self, action: "updateDatePickerLabel", forControlEvents: .ValueChanged)
updateDatePickerLabel()
}
func updateDatePickerLabel() {
dateDisplayLabel.text = dateFormatter.stringFromDate(date.date)
}
#lazy var dateFormatter: NSDateFormatter = {
let dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = .ShortStyle
return dateFormatter
}()
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//Events
#IBAction func btnAddTask_Click(sender: UIButton){
let appDel: foodforteethAppDelegate = UIApplication.sharedApplication().delegate as foodforteethAppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
let ent = NSEntityDescription.entityForName("Food", inManagedObjectContext: context)
var newFood = food(entity: ent, insertIntoManagedObjectContext: context)
newFood.foodname = txtTask.text
newFood.date = dateFormatter.stringFromDate(date.date)
context.save(nil)
/*
taskMgr.addTask(txtTask.text, desc: dateFormatter.stringFromDate(date.date));
self.view.endEditing(true)
txtTask.text = ""
//txtDesc.text = ""
//self.tabBarController.selectedIndex = 0;*/
self.navigationController.popViewControllerAnimated(true)
}
//iOS touch functions
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!){
self.view.endEditing(true)
}
func textFieldShouldReturn(textField: UITextField!) -> Bool {
textField.resignFirstResponder();
return true
}
}
You need to read https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
To import Swift code into Objective-C from the same target
Import the Swift code from that target into any Objective-C .m file
within that target using this syntax, and substituting the appropriate
name:
#import "ProductModuleName-Swift.h"
Any Swift files in your target will be visible in Objective-C .m files containing this import
statement. For information on using Swift from Objective-C code, see
Using Swift from Objective-C.
edit:
By adding QCAnnonce* a = [[QCAnnonce alloc] init];In my code somewhere before the function call, I solved the problem, so I guess that I "introduced the class to the runtime". But I have now a warning saying that "a" is unused, so is there a runtime function I can use to "introduce the class to the runtime"?
I am trying to create a client-server application. The objects are archived and unarchived for transmission using NSKeyed(Un)Archiver. Most of my objects are transmitted without any problem, but one of them raise an NSInvalidUnarchiveOperationException.
The exception is called before the breakpoint I placed in initWithCoder:.
I have tried to archive/unarchive before sending and this works well, so it shouldn't be an issue with initWithCoder.
I have tried to create a client in my server app (not in a separate app as my client) and he can decode the object. I can't see any difference between my client and this new client except that they are not in the same app.
The best guess I have is this part of the apple doc:
The delegate may, for example, load some code to introduce the class
to the runtime and return the class, or substitute a different class
object. If the delegate returns nil, unarchiving aborts and the method
raises an NSInvalidUnarchiveOperationException.
But I have no idea what "introduce the class to the runtime" means.
Here are this object methods for encoding/decoding:
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super init];
if (self) {
a_listeAnnonces = [aDecoder decodeObjectForKey:#"Cartes"];
a_points = [aDecoder decodeIntForKey:#"Points"];
}
return self;
}
-(void)encodeWithCoder:(NSCoder *)aCoder{
[aCoder encodeObject:a_listeAnnonces forKey:#"Cartes"];
[aCoder encodeInt:a_points forKey:#"Points"];
}
Here is the exception message:
2014-06-04 11:27:34.681 myApp[3693:303] *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (QCAnnonce)
2014-06-04 11:27:34.794 myApp[3693:303] (
0 CoreFoundation 0x00007fff8937a25c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8e898e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8937a10c +[NSException raise:format:] + 204
3 Foundation 0x00007fff8a8acdd9 _decodeObjectBinary + 2349
4 Foundation 0x00007fff8a8ac34d _decodeObject + 288
5 Foundation 0x00007fff8a8d15a5 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 92
6 myApp 0x000000010001365f -[QNProtocolWrap performMethod:withArgumentDatas:onObject:] + 543
7 myApp 0x000000010001261b -[QNConnection methodCall:withArguments:] + 251
8 myApp 0x0000000100012b23 -[QNConnection connectionBaseDidRecieveNewData:] + 211
9 myApp 0x0000000100012b8b -[QNConnection connectionBaseDidRecieveNewData:] + 315
10 myApp 0x000000010000e38c -[QNConnectionBase readInput] + 204
11 myApp 0x000000010000e591 -[QNConnectionBase stream:handleEvent:] + 449
12 CoreFoundation 0x00007fff892ebc81 _signalEventSync + 385
13 CoreFoundation 0x00007fff892ebac8 _cfstream_solo_signalEventSync + 328
14 CoreFoundation 0x00007fff892eb93f _CFStreamSignalEvent + 623
15 CFNetwork 0x00007fff81e4401a _ZN29CoreReadStreamCFStreamSupport19coreStreamReadEventEP16__CoreReadStreamm + 102
16 CFNetwork 0x00007fff81e43f89 _ZN20CoreReadStreamClient25coreStreamEventsAvailableEm + 53
17 CFNetwork 0x00007fff81f77a65 _ZN14CoreStreamBase14_callClientNowEP16CoreStreamClient + 53
18 CFNetwork 0x00007fff81e43ca9 _ZN14CoreStreamBase34_streamSetEventAndScheduleDeliveryEmh + 183
19 CFNetwork 0x00007fff81e43a32 _ZN12SocketStream40dispatchSignalFromSocketCallbackUnlockedEP24SocketStreamSignalHolder + 74
20 CFNetwork 0x00007fff81e43160 _ZN12SocketStream14socketCallbackEP10__CFSocketmPK8__CFDataPKv + 206
21 CFNetwork 0x00007fff81e43062 _ZN12SocketStream22_SocketCallBack_streamEP10__CFSocketmPK8__CFDataPKvPv + 64
22 CoreFoundation 0x00007fff892eb107 __CFSocketPerformV0 + 855
23 CoreFoundation 0x00007fff892ab661 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x00007fff8929cd12 __CFRunLoopDoSources0 + 242
25 CoreFoundation 0x00007fff8929c49f __CFRunLoopRun + 831
26 CoreFoundation 0x00007fff8929bf25 CFRunLoopRunSpecific + 309
27 HIToolbox 0x00007fff89726a0d RunCurrentEventLoopInMode + 226
28 HIToolbox 0x00007fff897267b7 ReceiveNextEventCommon + 479
29 HIToolbox 0x00007fff897265bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
30 AppKit 0x00007fff82a9526e _DPSNextEvent + 1434
31 AppKit 0x00007fff82a948bb -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
32 AppKit 0x00007fff82a889bc -[NSApplication run] + 553
33 AppKit 0x00007fff82a737a3 NSApplicationMain + 940
34 myApp 0x0000000100001262 main + 34
35 myApp 0x0000000100001234 start + 52
36 ??? 0x0000000000000003 0x0 + 3
)
It seems that Class is not loaded to runtime at the moment when you are trying to decode it by NSKeyedArchiver.
If it's not loaded, NSKeyedArchiver just can't find class QCAnnounce. (And that's why it can't decode it)
To check this, you may look in the + (void)load method of NSObject protocol.
The runtime sends this message once per a class right after the Class is loaded into process's address space.
For classes that are part of the program's executable file, the runtime sends the load message very early in the process's lifetime. For classes that are in a shared (dynamically-loaded) library, the runtime sends the load message just after the shared library is loaded into the process's address space.
You can check this by overloading +(void)load method and setting breakpoint there and see if it's have been loaded to runtime before you are calling unarchive.
+ (void)load {
NSLog(#"%# loaded!", self);
}
Your fix [[QCAnnounce alloc] init] works because when Runtime is trying to send first message to a class, it needs to call +(void)initialize to that class and by the time you receive initialize, class in your process should have already received load.
The problem here is that the runtime didn't load all the class present in my static library. As I had no direct call to that class (only id), it was never loaded.
I fixed it by adding -objC in "other linker flags" in the build settings.
Some informations about why this was a good idea were found in this Technical Q&A:
-objC causes the linker to load every object file in the library that defines an Objective-C class or category
There exists two others flags (same Q&A):
-all_load forces the linker to load all object files from every archive it sees, even those without Objective-C code. -force_load is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load option must be followed by a path to an archive, and every object file in that archive will be loaded.
Question:
I seem to have bindings set without design time or build errors, but at run-time an instance of a an NSManagedObject (an Account entity) isn't found. What is my configuration mistake?
Configuration:
This is a basic intro project. I've got a "no-code" solution by using XCode to auto generate most of an MVC application (not for iOS). Xcode generated an App Delegate with NSManagedObjectContext and a MainMenu.xib. To the xib, I added an NSObjectController, a Button used to create a new entity and a TextField to edit a value on the instance of the newly created entity. I created the data model, had XCode generate NSManagedObjects for my entities, and now I'm simply setting the bindings to connect the M-V-C.
Conceptual binding flows:
XIB's Button -> XIB's NSObjectController add: -> AppDelegate's managedObjectContext
AppDelegate's managedObjectContext -> NSObjectController's selection.name -> XIB's TextField
Button settings
Bindings: Sent Actions = add: --> ObjectController
ObjectController settings
Attributes: mode = Entity Name, value = Account, prepares content = true, Editable = true
Bindings; Parameters: bind to App Delegate, controller key = null, model key path = managedObjectContext
TextField settings
Bindings: Bind To = Object Controller, Controller Key = selection, Model Key Path = name
Problem:
There are no errors at design time or during build, and the run-time error log is below. I get the error when the XIB loads before I click the button. I get an identical error after I click the button. When the XIB loads, I'm guessing that the TextField is trying to fetch the column on a null entity. When I click the button, I'm guessing that the TextField doesn't have a handle to the instance that was created.
Error Log
2014-05-28 16:09:11.526 BingoAppServer[2060:303] Cannot perform operation since entity with name 'Account' cannot be found
2014-05-28 16:09:11.529 BingoAppServer[2060:303] (
0 CoreFoundation 0x00007fff933da25c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff98919e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff933da10c +[NSException raise:format:] + 204
3 AppKit 0x00007fff97020658 -[_NSManagedProxy _entity] + 141
4 AppKit 0x00007fff97020515 -[_NSManagedProxy fetchRequestWithSortDescriptors:limit:] + 95
5 AppKit 0x00007fff972708fb -[NSObjectController(NSManagedController) _executeFetch:didCommitSuccessfully:actionSender:] + 73
6 AppKit 0x00007fff9744b846 _NSSendCommitEditingSelector + 267
7 AppKit 0x00007fff970f4f78 -[NSController _controllerEditor:didCommit:contextInfo:] + 182
8 CoreFoundation 0x00007fff932c5a5c __invoking___ + 140
9 CoreFoundation 0x00007fff932c58c4 -[NSInvocation invoke] + 308
10 CoreFoundation 0x00007fff93368516 -[NSInvocation invokeWithTarget:] + 54
11 Foundation 0x00007fff934decb7 __NSFireDelayedPerform + 333
12 CoreFoundation 0x00007fff93341494 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
13 CoreFoundation 0x00007fff93340fcf __CFRunLoopDoTimer + 1151
14 CoreFoundation 0x00007fff933b25aa __CFRunLoopDoTimers + 298
15 CoreFoundation 0x00007fff932fc755 __CFRunLoopRun + 1525
16 CoreFoundation 0x00007fff932fbf25 CFRunLoopRunSpecific + 309
17 HIToolbox 0x00007fff8c772a0d RunCurrentEventLoopInMode + 226
18 HIToolbox 0x00007fff8c7727b7 ReceiveNextEventCommon + 479
19 HIToolbox 0x00007fff8c7725bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
20 AppKit 0x00007fff96cb326e _DPSNextEvent + 1434
21 AppKit 0x00007fff96cb28bb -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
22 AppKit 0x00007fff96ca69bc -[NSApplication run] + 553
23 AppKit 0x00007fff96c917a3 NSApplicationMain + 940
24 BingoAppServer 0x0000000100001252 main + 34
25 libdyld.dylib 0x00007fff915ec5fd start + 1
)
It's not saying it can't find this Account that you want — it's telling you it can't find the Account entity description in your managed object model at all. Check to ensure that you're using the right managed object model and that it has an entity named Account.
Your objectController's content shouldn't be bound to a managedObjectContext. It looks like what's happening is your object controller doesn't have a managed object context set, which is why the initial fetch is failing.
Your Object Controller's binding's should looks something more like:
objectController.entityName = #"Account";
objectController.automaticallyPreparesContrect = TRUE;
[objectController bind:#"managedObjectContext"
toObject:[NSApp delegate]
withKeyPath:#"managedObjectContext"
options:#{NSRaisesForNotApplicableKeysBindingOption : #(YES)
}];
button.target = objectController;
button.action = #selector(add:);
[textField bind:#"stringValue"
toObject:objectController
withKeyPath:#"selection.name"
options:#{NSConditionallySetsEditableBindingOption : #(YES),
NSNoSelectionPlaceholderBindingOption : #"No Selection"
/* etc... */
}];
You DON'T bind the managedObjectContext to the controller's path or value, that's not how it works. Formally, you don't have to bind this objectControllers value to anything in order to create a new Account and have it's props show up in the text field.
I have a button with two buttons which start the download of some data from a web server with RestKit.
Now if the user taps the two buttons repeatedly in quick succession my app crashes and produces the crash log below.
I initiate my requests like so:
-(void)loadDataAtPath:(NSString *)path completion:(ResultArrayBlock)completionBlock failed:(ResultFailedBlock)failedBlock
{
RKObjectMapping *groupMapping = [Group mapping];
[self.objectManager.mappingProvider setMapping:groupMapping forKeyPath:#"groups.group"];
[self.objectManager.mappingProvider setObjectMapping:groupMapping forKeyPath:path];
[self.objectManager loadObjectsAtResourcePath:path usingBlock:^(RKObjectLoader *loader) {
loader.onDidLoadObjects = ^(NSArray *array){
// Do the reverse mapping of the group
for (Group *c in array) {
for(Person *p in c.persons){
p.group = c;
}
}
completionBlock(array);
};
loader.onDidFailWithError = failedBlock;
}];
}
I first thought that the problem was the for-loop where I do some after-mapping setup of my data, but the problem still persists even when commenting the for-loop.
Curiously this problem does not occur in the simulator even when I switch on the Network Link Conditioner.prefpane
The crash
When I debug this on the device I get the following on the console.
[PLCrashReport] Terminated stack walking early: Corrupted frame
[PLCrashReport] Terminated stack walking early: Corrupted frame
The crash log looks like this:
Application Specific Information:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSCFDictionary: 0x3c14a0> was mutated while being enumerated.'
Last Exception Backtrace:
0 CoreFoundation 0x3734e88f __exceptionPreprocess + 162
1 libobjc.A.dylib 0x35053259 objc_exception_throw + 32
2 CoreFoundation 0x3734e3b3 __NSFastEnumerationMutationHandler + 162
3 MyApp 0x0008f5bf -[RKObjectMapper performKeyPathMappingUsingMappingDictionary:] + 407
4 MyApp 0x0008fa45 -[RKObjectMapper performMapping] + 673
5 MyApp 0x0008ac7d -[RKObjectLoader mapResponseWithMappingProvider:toObject:inContext:error:] + 1045
6 MyApp 0x0008b04f -[RKObjectLoader performMapping:] + 575
7 MyApp 0x0008b22b __47-[RKObjectLoader performMappingInDispatchQueue]_block_invoke_0 + 247
8 libdispatch.dylib 0x3046ec59 _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x30479cab _dispatch_queue_drain + 274
10 libdispatch.dylib 0x30479b19 _dispatch_queue_invoke$VARIANT$up + 36
11 libdispatch.dylib 0x3047a78b _dispatch_worker_thread2 + 214
12 libsystem_c.dylib 0x33bbddfb _pthread_wqthread + 294
13 libsystem_c.dylib 0x33bbdcd0 start_wqthread + 8
As #PhillipMills suggested, you can easily see the answer when you look inside performKeyPathMappingUsingMappingDictionary. Your problem is repeatedly setting the mapping with these lines:
[self.objectManager.mappingProvider setMapping:groupMapping forKeyPath:#"groups.group"];
[self.objectManager.mappingProvider setObjectMapping:groupMapping forKeyPath:path];
If you call this line while the response is being mapping it triggers the error because you are changing the same dictionary it is trying to fast enumerate over.
Normally, you would set the mapping somewhere in the initial configuration and NOT each time like this.