App Crashes on Add (Sometimes)


While my CarLot app seems to function fine, I notice that if I press the Add button when the previous car is still highlighted, the app crashes. Xcode goes to AppDelegate.swift and I see a message that starts with EXC_BAD_ACCESS. If I click the window first to remove the highlighting, the Add button works fine. I’ve posted a screen shot at If I press the Add button at this point, the app crashes. This isn’t normal behavior surely? Does your app act like this? Is this something I’ve done wrong, or is it just a detail that the carLot example doesn’t address?

BTW, is there a way to paste an image directly in the post? I can’t figure out what the Img button does.


I’m not having this problem with my code. If you want to post your code to github I’ll take a look at it to see if I can figure out what’s going on.

About posting images, the moderator of each chapter’s forum has the ability to allow or disallow posting of attachments, etc. It hasn’t been allowed for this chapter.


Thanks a lot. I put my code at I went through it again after reading that you don’t have this problem, and I noticed something I had overlooked before. The bolding of the first two columns if the car is on special isn’t working either, although my screen looks just like Figure 13.18 in the book, so far as I can see.


Hi Saul, the Add button has an unneeded Target binding that is causing the crash. Control-click the Add button in Interface Builder and delete that Target binding to fix it.

I’m not sure yet what’s happening with the bolding problem. Everything so far looks proper to me.

I may have mentioned this before, perhaps to someone else I helped on a similar problem with the program crashing for unknown reasons. What I do is open my project and the book’s project code in two side-by-side windows. Then I can go through swift code line-by-line, or Interface Builder objects object-by-object comparing Bindings, Connections, Settings, etc. Eventually I find something that I’ve done differently from the book and fixing that usually fixes the problem. This is after making sure the book’s code doesn’t exhibit the same problems. :wink:


Thanks again. That fixed the crashing problem. As to comparing the code with the book’s, what I’ve been doing is going back to the beginning of the chapter and trying to make sure that I’ve followed the instructions. I think I’ll try downloading the code and see if that helps.


My App also crashes as soon I click “Add”

[quote]2015-11-07 10:54:52.066 CarLot[5234:223306] Cannot remove an observer <NSAutounbinderObservance 0x608000039f00> for the key path “objectValue.makeModel” from <NSTableCellView 0x6080001853b0>, most likely because the value for the key “objectValue” has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the NSTableCellView class.
2015-11-07 10:54:52.076 CarLot[5234:223306] (
0 CoreFoundation 0x00007fff9481ce32 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff8a815dd4 objc_exception_throw + 48
2 CoreFoundation 0x00007fff9488365d +[NSException raise:format:] + 205
3 Foundation 0x00007fff93db3014 -[NSKeyValueNestedProperty object:didRemoveObservance:recurse:] + 793
4 Foundation 0x00007fff93d9ea53 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 261
5 Foundation 0x00007fff93d9e8f3 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 108
6 AppKit 0x00007fff856afa2b -[NSAutounbinder removeObserver:forKeyPath:] + 195
7 AppKit 0x00007fff85604d6f -[NSBinder _updateObservingRegistration:] + 745
8 AppKit 0x00007fff85606058 -[NSBinder breakConnection] + 104
9 AppKit 0x00007fff855fceaf -[NSObject(NSKeyValueBindingCreation) unbind:] + 195
10 AppKit 0x00007fff856af87c -[NSAutounbinder retainBindingTargetAndUnbind] + 163
11 AppKit 0x00007fff856a6379 -[NSTableCellView release] + 110
12 CoreFoundation 0x00007fff9473656d -[__NSArrayM dealloc] + 205
13 libobjc.A.dylib 0x00007fff8a80b094 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 476
14 QuartzCore 0x00007fff8f1ec1ad _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 185
16 CoreFoundation 0x00007fff947b2007 __CFRunLoopDoObservers + 391
17 CoreFoundation 0x00007fff94790fe8 CFRunLoopRunSpecific + 328
18 HIToolbox 0x00007fff89739d55 RunCurrentEventLoopInMode + 235
19 HIToolbox 0x00007fff89739a97 ReceiveNextEventCommon + 184
20 HIToolbox 0x00007fff897399cf _BlockUntilNextEventMatchingListInModeWithFilter + 71
21 AppKit 0x00007fff855a2d96 _DPSNextEvent + 1067
22 AppKit 0x00007fff855a21c5 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
23 AppKit 0x00007fff85596d28 -[NSApplication run] + 682
24 AppKit 0x00007fff8555ffbe NSApplicationMain + 1176
25 CarLot 0x0000000100002187 main + 87
26 libdyld.dylib 0x00007fff8bad65ad start + 1

Can somebody help? :frowning:


I’m getting a crash on Add every time and am pretty frustrated.
The Add Button has a sent action to Cars, add
The Cars controller is bound managedObjectContext to File’s Owner managedObjectContext
And the File’s Owner is confirmed to be Document.xcdatamodeld

But every time I press it, NSApplication crashes in Thread One with EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). In the past, that has usually meant some miss-spelling, but at this point, I haven’t written a line of code, just specified an entity and a user interface and done the bindings.

Any ideas?



When you bound the Cars controller to File’s Owner managedObjectContext, did you do it under Parameters and not Controller Content? And I’m assuming you followed all the steps setting up the Cars array controller. Like in the Identity inspector and so on.

My suggestion would be to review each step, and each binding. If you have done that and everything still appears correct from what the book is tell you to do and it still crashes, then I’d delete the project and start it over. There have been cases here where Xcode gets some kind of bug in there and once a project is redone, it works…even if you did the exact same thing.