AnsweredAssumed Answered

iOS App SDK 17 + Swift app delegate = crash

Question asked by Brian Hamm on Jun 15, 2018
Latest reply on Oct 23, 2018 by sfpx

Product and version

Xcode 9.4

 

OS and version

macOS 10.13.5, FileMaker iOS App SDK 17.0.2

 

Hardware

Retina MacBook Pro 13"

 

Description

The documentation for the iOS App SDK v17 states:

 

To add your own app delegate, add the Swift or Objective-C file that includes the app delegate to your project in Xcode. Then use the applicationDelegateClass option in configFile.txt to specify the name of the class that defines your app delegate. When the app launches, an instance of the class is created to receive the UIApplicationDelegate messages.

 

If I add an Objective-C app delegate such as `myAppDel.h`, and assign it in `configFile.txt`, everything works fine. I can build and run a FIAS app in the Xcode Simulator or on device, and my app delegate callback methods fire as expected.

 

If I add a Swift app delegate, the FIAS app builds successfully, attemps to run, and crashes on launch with the following error to the console:

 

2018-06-13 20:41:36.651031-0500 fmswift[54308:6131426] setupExternalDelegate:  Failed to find delegate class named myAppDel

2018-06-13 20:41:36.652962-0500 fmswift[54308:6131426] Exception caught: Specified delegate class not found

2018-06-13 20:41:36.669801-0500 fmswift[54308:6131426] 0x1108391ce: 0   CoreFoundation                      0x00000001108391e6 __exceptionPreprocess + 294

2018-06-13 20:41:36.670819-0500 fmswift[54308:6131426] 0x10861e031: 1   libobjc.A.dylib                     0x000000010861e031 objc_exception_throw + 48

2018-06-13 20:41:36.671746-0500 fmswift[54308:6131426] 0x10671cb82: 2   iOSAppSDK                           0x000000010671cb82 -[FMClientAppDelegate setupExternalDelegate] + 290

2018-06-13 20:41:36.672504-0500 fmswift[54308:6131426] 0x106718968: 3   iOSAppSDK                           0x0000000106718968 -[FMClientAppDelegate init] + 72

2018-06-13 20:41:36.673031-0500 fmswift[54308:6131426] 0x109102664: 4   UIKit                               0x0000000109102664 _UIApplicationMainPreparations + 1491

2018-06-13 20:41:36.675157-0500 fmswift[54308:6131426] 0x109102027: 5   UIKit                               0x0000000109102027 UIApplicationMain + 111

2018-06-13 20:41:36.676009-0500 fmswift[54308:6131426] 0x106820611: 6   iOSAppSDK                           0x0000000106820611 _Z8startAppiPPcPKhPKyS2_S4_ + 305

2018-06-13 20:41:36.676637-0500 fmswift[54308:6131426] 0x11162a955: 7   libdyld.dylib                       0x000000011162a955 start + 1

2018-06-13 20:41:36.677554-0500 fmswift[54308:6131426] 0x1: 8   ???                                 0x0000000000000001 0x0 + 1

 

 

How to replicate

Create a new Xcode project via the Terminal, per the FIAS documentation. In the Xcode project, open `configFile.txt` and assign a custom delegate. Create a delegate class with File > New File > Swift File, and include a delegate method(s):

 

import UIKit

 

class myAppDel: UIResponder, UIApplicationDelegate {

   

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

       

        print("app delegate!")

        return true

    }

    //...

}

 

 

Workaround (if any)

None that I've been able to determine. I've tried flagging `myAppDel` with @objc and I've experimented a little with `Bridging-Header.h`. No change when using the PlaceHolder.fmp12 or a custom Go solution file. No change when including (or not) a file extension in the config file... ie. `myAppDel.swift` vs. `myAppDel`. No change after clean-building the project folder (Shift-Option-Command-K).

Outcomes