Error on run

I am just starting and am confused about what to do with this error.

2018-03-03 17:29:47.223293-0500 Chewculator[14245:374098] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Chewculator.ViewController 0x7f855276c0e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key allclearPressed.'

*** First throw call stack:

(

0 CoreFoundation 0x0000000108dfe12b __exceptionPreprocess + 171

1 libobjc.A.dylib 0x00000001049f7f41 objc_exception_throw + 48

2 CoreFoundation 0x0000000108dfe079 -[NSException raise] + 9

3 Foundation 0x0000000104416a63 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292

4 UIKit 0x0000000105b47117 -[UIViewController setValue:forKey:] + 87

5 UIKit 0x0000000105e38c2d -[UIRuntimeOutletConnection connect] + 109

6 CoreFoundation 0x0000000108da13cd -[NSArray makeObjectsPerformSelector:] + 317

7 UIKit 0x0000000105e375e3 -[UINib instantiateWithOwner:options:] + 1856

8 UIKit 0x0000000105b4e3ff -[UIViewController _loadViewFromNibNamed:bundle:] + 383

9 UIKit 0x0000000105b4ed2b -[UIViewController loadView] + 177

10 UIKit 0x0000000105b4f05c -[UIViewController loadViewIfRequired] + 195

11 UIKit 0x0000000105b4f8b9 -[UIViewController view] + 27

12 UIKit 0x0000000105a1a7cf -[UIWindow addRootViewControllerViewIfPossible] + 122

13 UIKit 0x0000000105a1aed7 -[UIWindow _setHidden:forced:] + 294

14 UIKit 0x0000000122342bdd -[UIWindowAccessibility _orderFrontWithoutMakingKey] + 86

15 UIKit 0x0000000105a2de54 -[UIWindow makeKeyAndVisible] + 42

16 UIKit 0x00000001059a08b8 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4737

17 UIKit 0x00000001059a5aeb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720

18 UIKit 0x0000000105d6f6f8 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924

19 UIKit 0x00000001061454c8 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153

20 UIKit 0x0000000105d6f2f1 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249

21 UIKit 0x0000000105d6fb6b -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 696

22 UIKit 0x00000001066eda69 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262

23 UIKit 0x00000001066ed922 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444

24 UIKit 0x00000001063ca9c8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221

25 UIKit 0x00000001065c9b06 _performActionsWithDelayForTransitionContext + 100

26 UIKit 0x00000001063ca88b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231

27 UIKit 0x0000000106144b25 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392

28 UIKit 0x00000001059a436a -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523

29 UIKit 0x0000000105f7f605 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369

30 FrontBoardServices 0x000000010bdc1cc0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338

31 FrontBoardServices 0x000000010bdca7b5 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235

32 libdispatch.dylib 0x0000000109f201ba _dispatch_client_callout + 8

33 libdispatch.dylib 0x0000000109f25468 _dispatch_block_invoke_direct + 324

34 FrontBoardServices 0x000000010bdf6498 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24

35 FrontBoardServices 0x000000010bdf614e -[FBSSerialQueue _performNext] + 464

36 FrontBoardServices 0x000000010bdf66bd -[FBSSerialQueue _performNextFromRunLoopSource] + 45

37 CoreFoundation 0x0000000108da1101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

38 CoreFoundation 0x0000000108e40f71 __CFRunLoopDoSource0 + 81

39 CoreFoundation 0x0000000108d85a19 __CFRunLoopDoSources0 + 185

40 CoreFoundation 0x0000000108d84fff __CFRunLoopRun + 1279

41 CoreFoundation 0x0000000108d84889 CFRunLoopRunSpecific + 409

42 GraphicsServices 0x000000010c68a9c6 GSEventRunModal + 62

43 UIKit 0x00000001059a75d6 UIApplicationMain + 159

44 Chewculator 0x00000001040e25f7 main + 55

45 libdyld.dylib 0x0000000109f94d81 start + 1

)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)


It seems to be from this area.

}

func allclearPressed(_ sender: RoundButton) {

runningNumber = ""

leftValue = ""

rightValue = ""

result = ""

currentOperation = .NULL

outputlab.text = "0"

}

func dotPressed(_ sender: RoundButton) {

if runningNumber.count <= 7 {

runningNumber += "."

outputlab.text = runningNumber

}

}

Replies

This is the same question you asked before, right?


The problem is that your action methods (allclearPressed and dotPressed) are pure Swift methods, not @objc methods as required by the target/action mechanism you're using to handle button presses.


Action methods should be give the @IBAction annotation, which implies @objc. You can just put @obj if you want, but @IBAction is preferred.


Note: As of Swift 4, methods in @obj classes are not automatically assumed to be @obj, as they were in Swift 3.