SwiftUI iOS app: crashes immediately on startup in AppDelegate in iOS 15

An unchanged App which run fine in < iOS 15 versions crashes directly on startup in iOS 15.0.1.

Reason is unclear for me. Tried debugging in Xcode 13 - no hints at all. Has someone an idea?

2021-10-06 13:50:13.392174+0200 MyS&N[11966:313647] -[__NSSingleObjectArrayI stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance 0x600001a38350

2021-10-06 13:50:13.468528+0200 MyS&N[11966:313647] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectArrayI stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance 0x600001a38350'

*** First throw call stack:

(

	0   CoreFoundation                      0x00007fff203fbbb4 __exceptionPreprocess + 242

	1   libobjc.A.dylib                     0x00007fff2019ebe7 objc_exception_throw + 48

	2   CoreFoundation                      0x00007fff2040a821 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0

	3   CoreFoundation                      0x00007fff204000bc ___forwarding___ + 1433

	4   CoreFoundation                      0x00007fff204021e8 _CF_forwarding_prep_0 + 120

	5   UIKitCore                           0x00007fff2501951a +[UIApplication _sanitizeBundleString:] + 83

	6   UIKitCore                           0x00007fff250192bf __41+[UIApplication _applicationNameForMenus]_block_invoke + 443

	7   libdispatch.dylib                   0x0000000104a5ec0c _dispatch_client_callout + 8

	8   libdispatch.dylib                   0x0000000104a6016d _dispatch_once_callout + 66

	9   UIKitCore                           0x00007fff25019102 +[UIApplication _applicationNameForMenus] + 97

	10  UIKitCore                           0x00007fff25402b54 __42+[UIMenu(DefaultMenus) _defaultMenuTitles]_block_invoke + 80

	11  libdispatch.dylib                   0x0000000104a5ec0c _dispatch_client_callout + 8

	12  libdispatch.dylib                   0x0000000104a6016d _dispatch_once_callout + 66

	13  UIKitCore                           0x00007fff25402b02 +[UIMenu(DefaultMenus) _defaultMenuTitles] + 46

	14  UIKitCore                           0x00007fff254032d9 +[UIMenu(DefaultMenus) _defaultInlineMenuWithIdentifier:children:] + 70

	15  UIKitCore                           0x00007fff2439472b -[_UIMainMenuSystem _init] + 131

	16  UIKitCore                           0x00007fff24394693 __34+[_UIMainMenuSystem _sharedSystem]_block_invoke + 29

	17  libdispatch.dylib                   0x0000000104a5ec0c _dispatch_client_callout + 8

	18  libdispatch.dylib                   0x0000000104a6016d _dispatch_once_callout + 66

	19  UIKitCore                           0x00007fff24394674 +[_UIMainMenuSystem _sharedSystem] + 97

	20  UIKitCore                           0x00007fff2501e6d2 -[UIApplication _keyCommands] + 96

	21  UIKitCore                           0x00007fff25034368 -[UIResponder _enumerateKeyCommandsInChainWithOptions:usingBlock:] + 674

	22  UIKitCore                           0x00007fff2501e150 -[UIApplication _updateSerializableKeyCommandsForResponder:] + 199

	23  UIKitCore                           0x00007fff24ff8026 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 733

	24  UIKitCore                           0x00007fff24ff9a91 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 4115

	25  UIKitCore                           0x00007fff24fff403 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1221

	26  UIKitCore                           0x00007fff245806a1 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 179

	27  UIKitCore                           0x00007fff24ffbab6 -[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 59

	28  UIKitCore                           0x00007fff24ffbe55 -[UIApplication _run] + 914

	29  UIKitCore                           0x00007fff25000a53 UIApplicationMain + 101

	30  SwiftUI                             0x00007fff5cb0d6a3 $s7SwiftUI17KitRendererCommon33_ACC2C5639A7D76F611E170E831FCA491LLys5NeverOyXlXpFAESpySpys4Int8VGSgGXEfU_ + 196

	31  SwiftUI                             0x00007fff5cb0d5dd $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 148

	32  SwiftUI                             0x00007fff5c4eece1 $s7SwiftUI3AppPAAE4mainyyFZ + 61

	33  MyS&N                               0x0000000103a236ae $s5MyS_N0A5SNAppV5$mainyyFZ + 30

	34  MyS&N                               0x0000000103a23729 main + 9

	35  dyld                                0x00000001048dbe1e start_sim + 10

	36  ???                                 0x0000000000000001 0x0 + 1

)

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

dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_LIBRARY_PATH=/Users/markusmalik/Library/Developer/Xcode/DerivedData/MySN-eqsiruneqfkgiyfezjyjnfrjofbi/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib DYLD_FRAMEWORK_PATH=/Users/markusmalik/Library/Developer/Xcode/DerivedData/MySN-eqsiruneqfkgiyfezjyjnfrjofbi/Build/Products/Debug-iphonesimulator:/Users/markusmalik/Library/Developer/Xcode/DerivedData/MySN-eqsiruneqfkgiyfezjyjnfrjofbi/Build/Products/Debug-iphonesimulator/PackageFrameworks

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectArrayI stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance 0x600001a38350'

terminating with uncaught exception of type NSException

CoreSimulator 776.3 - Device: iPhone Xʀ (EE1B1F60-043B-4FF8-A2FD-3F82DA858B50) - Runtime: iOS 15.0 (19A339) - DeviceType: iPhone Xʀ
code-block

Not sure you crashed in AppDelegate, that's only the point where debugger returns after crash.

Did you try a Clean Build Folder ?

You should show some code:

  • Complete code of SceneDelegate
  • Complete code of ContentView (the one called in SceneDelegate)
  • info.plist

That will help investigate the problem.

Yes, I tried everything. Cleaning build folder of course, several times. I appreciate your help - sorry for the delayed answer!!

The requested files in the my following answers:

SceneDelegate:

import UIKit

import SwiftUI



class SceneDelegate: UIResponder, UIWindowSceneDelegate {



    var window: UIWindow?





    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.

        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.

        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).



        

        // Create the SwiftUI view that provides the window contents.

//        let contentView = ContentView() // übergebe Daten

        

        let contentView = ContentView().environmentObject(GlobalData())

        

        // Use a UIHostingController as window root view controller.

        if let windowScene = scene as? UIWindowScene {

            let window = UIWindow(windowScene: windowScene)

            window.rootViewController = UIHostingController(rootView: contentView)

            self.window = window

            window.makeKeyAndVisible()

        }

    }



    func sceneDidDisconnect(_ scene: UIScene) {

        // Called as the scene is being released by the system.

        // This occurs shortly after the scene enters the background, or when its session is discarded.

        // Release any resources associated with this scene that can be re-created the next time the scene connects.

        // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).

    }



    func sceneDidBecomeActive(_ scene: UIScene) {

        // Called when the scene has moved from an inactive state to an active state.

        // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.

    }



    func sceneWillResignActive(_ scene: UIScene) {

        // Called when the scene will move from an active state to an inactive state.

        // This may occur due to temporary interruptions (ex. an incoming phone call).

    }



    func sceneWillEnterForeground(_ scene: UIScene) {

        // Called as the scene transitions from the background to the foreground.

        // Use this method to undo the changes made on entering the background.

    }



    func sceneDidEnterBackground(_ scene: UIScene) {

        // Called as the scene transitions from the foreground to the background.

        // Use this method to save data, release shared resources, and store enough scene-specific state information

        // to restore the scene back to its current state.

        

        // Schedule die nächste Background-App-Aufruf

//        (UIApplication.shared.delegate as! AppDelegate).scheduleBackgroundFetch()

    }





}

ContentView: is too big, I cannot post it here.

Info.plist:


<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

	<key></key>

	<string></string>

	<key>CFBundleDevelopmentRegion</key>

	<string>$(DEVELOPMENT_LANGUAGE)</string>

	<key>CFBundleDisplayName</key>

	<array>

		<string></string>

	</array>

	<key>CFBundleExecutable</key>

	<string>$(EXECUTABLE_NAME)</string>

	<key>CFBundleIdentifier</key>

	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>

	<key>CFBundleInfoDictionaryVersion</key>

	<string>6.0</string>

	<key>CFBundleName</key>

	<string>$(PRODUCT_NAME)</string>

	<key>CFBundlePackageType</key>

	<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>

	<key>CFBundleShortVersionString</key>

	<string>$(MARKETING_VERSION)</string>

	<key>CFBundleVersion</key>

	<string>$(CURRENT_PROJECT_VERSION)</string>

	<key>ITSAppUsesNonExemptEncryption</key>

	<false/>

	<key>LSApplicationCategoryType</key>

	<string>Enterprise Utility</string>

	<key>LSRequiresIPhoneOS</key>

	<true/>

	<key>NSBonjourServices</key>

	<array>

		<string>_MySN-BS._tcp</string>

		<string>_MySN-BS._udp</string>

		<string>_MySN-5Win._tcp</string>

		<string>_MySN-5Win._udp</string>

	</array>

	<key>NSLocalNetworkUsageDescription</key>

	<string>Wird benötigt um 5 gewinnt und Schiffe versenken im Multiplayer zu spielen</string>

	<key>UIApplicationSceneManifest</key>

	<dict>

		<key>UIApplicationSupportsMultipleScenes</key>

		<false/>

		<key>UISceneConfigurations</key>

		<dict>

			<key>UIWindowSceneSessionRoleApplication</key>

			<array>

				<dict>

					<key>UISceneConfigurationName</key>

					<string>Default Configuration</string>

					<key>UISceneDelegateClassName</key>

					<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>

				</dict>

			</array>

		</dict>

	</dict>

	<key>UILaunchStoryboardName</key>

	<string>LaunchScreen</string>

	<key>UIRequiredDeviceCapabilities</key>

	<array>

		<string>armv7</string>

	</array>

	<key>UISupportedInterfaceOrientations</key>

	<array>

		<string>UIInterfaceOrientationPortrait</string>

		<string>UIInterfaceOrientationLandscapeLeft</string>

		<string>UIInterfaceOrientationLandscapeRight</string>

		<string>UIInterfaceOrientationPortraitUpsideDown</string>

	</array>

	<key>UISupportedInterfaceOrientations~ipad</key>

	<array>

		<string>UIInterfaceOrientationPortrait</string>

		<string>UIInterfaceOrientationPortraitUpsideDown</string>

		<string>UIInterfaceOrientationLandscapeLeft</string>

		<string>UIInterfaceOrientationLandscapeRight</string>

	</array>

	<key>UIUserInterfaceStyle</key>

	<string>Light</string>

</dict>

</plist>

Same issue happen with me. Adding Display name explicitly fixed the issue for me. Select Target -> General and check display name is explicitly added.

Hi manish_cs!

MANY, MANY, MANY THANKS!!!!!

That did it! No crash at startup anymore - I was going crazy about this.

What a simple solution - it would have never came to my mind.

Alignments are broken in SWIFTUI still - but now i can work on it.

Strange behaviour: what was left aligned is sometime now center...

SwiftUI iOS app: crashes immediately on startup in AppDelegate in iOS 15
 
 
Q