Unrecognized Selector Sent to Instance

Exception NSException * "-[UIView setDelegate:]: unrecognized selector sent to instance 0x7f82d74110c0" 0x0000600000826760

Hello! I am very new to Swift and could really use some guidance as I am getting started. I have done my best to try to solve this using tutorials and other resources. I keep getting this error when I try to run. Thank you in advance and please be kind, I am learning!

This is the message I am receiving:

2020-06-09 22:35:59.033443-0400 The Golf Club[11534:3724081] -[UIView setDelegate:]: unrecognized selector sent to instance 0x7f82d74110c0
2020-06-09 22:35:59.127870-0400 The Golf Club[11534:3724081] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setDelegate:]: unrecognized selector sent to instance 0x7f82d74110c0'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23e39f0e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50ad79b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23e5ac34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKitCore 0x00007fff48bf7058 -[UIResponder doesNotRecognizeSelector:] + 302
4 CoreFoundation 0x00007fff23e3e90c forwarding + 1436
5 CoreFoundation 0x00007fff23e40bf8 _CF_forwarding_prep_0 + 120
6 The Golf Club 0x000000010be40422 $s13The_Golf_Club14ViewControllerC11viewDidLoadyyF + 322
7 The Golf Club 0x000000010be4089b $s13The_Golf_Club14ViewControllerC11viewDidLoadyyFTo + 43
8 UIKitCore 0x00007fff4851adb6 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 83
9 UIKitCore 0x00007fff4851fcd4 -[UIViewController loadViewIfRequired] + 1084
10 UIKitCore 0x00007fff485200f1 -[UIViewController view] + 27
11 UIKitCore 0x00007fff48c00841 -[UIWindow addRootViewControllerViewIfPossible] + 326
12 UIKitCore 0x00007fff48bffe6a -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 219
13 UIKitCore 0x00007fff48c00ef5 -[UIWindow _setHidden:forced:] + 362
14 UIKitCore 0x00007fff48c1431c -[UIWindow _mainQueue_makeKeyAndVisible] + 42
15 UIKitCore 0x00007fff48e33a8c -[UIWindowScene _makeKeyAndVisibleIfNeeded] + 202
16 UIKitCore 0x00007fff48126470 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1405
17 UIKitCore 0x00007fff48bc42c1 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1019
18 UIKitCore 0x00007fff48bc45f8 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 291
19 UIKitCore 0x00007fff48718ec0 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
20 FrontBoardServices 0x00007fff36c35d2e -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 419
21 FrontBoardServices 0x00007fff36c5bdc1 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102
22 FrontBoardServices 0x00007fff36c40757 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220
23 FrontBoardServices 0x00007fff36c5ba52 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355
24 libdispatch.dylib 0x000000010c0bde8e _dispatch_client_callout + 8
25 libdispatch.dylib 0x000000010c0c0da2 _dispatch_block_invoke_direct + 300
26 FrontBoardServices 0x00007fff36c816e9 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 30
27 FrontBoardServices 0x00007fff36c813d7 -[FBSSerialQueue _queue_performNextIfPossible] + 441
28 FrontBoardServices 0x00007fff36c818e6 -[FBSSerialQueue _performNextFromRunLoopSource] + 22
29 CoreFoundation 0x00007fff23d9deb1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
30 CoreFoundation 0x00007fff23d9dddc __CFRunLoopDoSource0 + 76
31 CoreFoundation 0x00007fff23d9d60c __CFRunLoopDoSources0 + 268
32 CoreFoundation 0x00007fff23d981ae __CFRunLoopRun + 974
33 CoreFoundation 0x00007fff23d97ac4 CFRunLoopRunSpecific + 404
34 GraphicsServices 0x00007fff38b2fc1a GSEventRunModal + 139
35 UIKitCore 0x00007fff48bc7f80 UIApplicationMain + 1605
36 The Golf Club 0x000000010be432cb main + 75
37 libdyld.dylib 0x00007fff519521fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

HERE IS THE CODE:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    return true
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

}

Your app delegate looks fine. The problem is elsewhere, perhaps in The_Golf_ClubViewController. I’m probably getting the terminology wrong, but “unrecognized selector” means you’re asking an Objective-C object or class to run a function that it doesn’t implement. (Functions work differently in Objective-C than in Swift and therefore use different terminology like “selector”.) In this case, you are asking UIView or perhaps an instance thereof to run a function called setDelegate. Because there is no implementation, the crash happens.

To see what line is causing the crash, you could set an exception breakpoint and rerun. This is the first thing I do when I see a crash bubble up to the app delegate.

As as aside, Swift symbols generally use, by convention, camel case rather than snake case. TheGolfClubViewController is an example of camel case.

1 Like