Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Vending Machine App in Swift Using the Vending Machine Updating the Price

Joshua Walker
Joshua Walker
2,547 Points

Build vending machine crash when hitting the purchase button, Whats happening?

When i hit the purchase button my app crashes, and i cant understand what went wrong, i have been following along and cant figure out what I'm missing

2016-12-30 16:56:05.976 VendingMachine[21066:5136373] -[VendingMachine.ViewController purchase:]: unrecognized selector sent to instance 0x7f8004c01e80 2016-12-30 16:56:05.980 VendingMachine[21066:5136373] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VendingMachine.ViewController purchase:]: unrecognized selector sent to instance 0x7f8004c01e80' *** First throw call stack: ( 0 CoreFoundation 0x00000001091c7d4b exceptionPreprocess + 171 1 libobjc.A.dylib 0x0000000108c2921e objc_exception_throw + 48 2 CoreFoundation 0x0000000109237f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x000000010914d005 ___forwarding_ + 1013 4 CoreFoundation 0x000000010914cb88 CF_forwarding_prep_0 + 120 5 UIKit 0x0000000109d008bc -[UIApplication sendAction:to:from:forEvent:] + 83 6 UIKit 0x0000000109e86c38 -[UIControl sendAction:to:forEvent:] + 67 7 UIKit 0x0000000109e86f51 -[UIControl _sendActionsForEvents:withEvent:] + 444 8 UIKit 0x0000000109e85e4d -[UIControl touchesEnded:withEvent:] + 668 9 UIKit 0x0000000109d6e545 -[UIWindow _sendTouchesForEvent:] + 2747 10 UIKit 0x0000000109d6fc33 -[UIWindow sendEvent:] + 4011 11 UIKit 0x0000000109d1c9ab -[UIApplication sendEvent:] + 371 12 UIKit 0x000000010a50972d __dispatchPreprocessedEventFromEventQueue + 3248 13 UIKit 0x000000010a502463 __handleEventQueue + 4879 14 CoreFoundation 0x000000010916c761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION_ + 17 15 CoreFoundation 0x000000010915198c __CFRunLoopDoSources0 + 556 16 CoreFoundation 0x0000000109150e76 __CFRunLoopRun + 918 17 CoreFoundation 0x0000000109150884 CFRunLoopRunSpecific + 420 18 GraphicsServices 0x000000010ee97a6f GSEventRunModal + 161 19 UIKit 0x0000000109cfec68 UIApplicationMain + 159 20 VendingMachine 0x000000010862be2f main + 111 21 libdyld.dylib 0x000000010cfd968d start + 1 22 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

5 Answers

Joshua, I had the same issue as I was following along. I was able to fix the issue when I looks at the outlet for the purchase button. There were actually two events up "touch up inside," which will cause the app to crash because they are both pointing to the same selector. Delete both of them, and with both the view controller and the storyboard up, control-drag from the empty circle to the left of the purchase function to the purchase button. Try running again. If this didn't help or you didn't understand something, I can send screenshots.

I hope this helps.

krystennant
krystennant
7,197 Points

Thank you - this worked for me.

Wesley Jacobs
Wesley Jacobs
5,865 Points

Right clicking and removing the "Touch up inside" completely and reconnecting the purchase action did it for me! Thank you*

Kareem Jeiroudi
Kareem Jeiroudi
14,984 Points

Seriously thanks a lot for sharing this answer! I've debugging the application for over 2 hours now, and couldn't understand why this exception was occurring. For me, the issue that there were apparently two mapped actions to the ViewController.

Anthony Attard
Anthony Attard
43,915 Points

Same thing happened to me except that I had somehow deleted the connection between the button push and the purchase function. Simply reconnected them and everything is working fine.

charles wilson
charles wilson
8,506 Points

I've deleted all action events associated with the purchase function, but I'm not able to get this to work.

andrew falcone
andrew falcone
8,651 Points

I had the same problem, but I accidentally added the word 'throws' after the purchase function. DON'T do that.

thanks @timneuburg