Crash on launch from all TestFlight builds, but when loading the app from Xcode

We are preparing a launch for iOS 18, and we experienced crashes from iOS 17 devices. If I load the app right from Xcode 16 RC to the iOS 17 device, then it works fine, but if I download it from TestFlight, the nit crashes.

The app crashes immediately upon launch due to a missing symbol in the Foundation framework. I'm hoping someone can provide insights or suggestions on how to resolve this.

Error Message

CopySymbol not found: _$s10Foundation14NSDecimalRoundyySpySo0B0aG_SPyADGSiSo14NSRoundingModeVtF
Referenced from: <C1ABDA48-29EE-3674-8554-669220A76F81> /Volumes/VOLUME/*/CamPlan.app/CamPlan
Expected in: <D92E19C1-6299-3E94-8614-C505D5ABCCDB> /System/Library/Frameworks/Foundation.framework/Foundation

What I've Tried

Verified that the app is compiled with the latest Xcode version Checked for any usage of private APIs (none found) Reviewed usage of Foundation framework methods, especially those related to NSDecimalRound

Questions

What could be causing this symbol to be missing? Are there any known issues with NSDecimalRound or related functions in recent iOS versions? How can I identify which part of my code is trying to use this missing symbol?

Answered by DTS Engineer in 803544022

Hmmm, this is ringing lots of bell. Have you seen the known issue in the Foundation section of the Xcode 16 RC Release Notes?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Hmmm, this is ringing lots of bell. Have you seen the known issue in the Foundation section of the Xcode 16 RC Release Notes?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

There is a related thread here with a workaround that I've been able to use: https://developer.apple.com/forums/thread/762711

The RC Release Notes don't explicitly mention NSDecimalRound but given what it says in there about the other NSDecimal* functions, I assume it's affected. The RC notes should be updated to include this function as well, imo.

We also had unexpected crashes on launch on iOS 17 due to using NSDecimalRound. We have followed the suggestion from the known issues in the Xcode 16 RC Release notes by writing a designated class in Objective C and calling the NSDecimalRound function from objective C instead of from Swift. This prevents the crash.

Below our code:

//  DecimalRoundFix.m

#import "DecimalRoundFix.h"

@implementation DecimalRoundFix

+(void)round:(nonnull NSDecimal *)result number: (nonnull NSDecimal *)number scale: (NSInteger) scale roundingMode: (NSRoundingMode) roundingMode {
    NSDecimalRound(result, number, scale, roundingMode);
}

@end

// DecimalRoundFix.h


#import <Foundation/Foundation.h>

@interface DecimalRoundFix : NSObject {
    
}

+(void)round:(nonnull NSDecimal *)result number: (nonnull NSDecimal *)number scale:(NSInteger) scale roundingMode: (NSRoundingMode) roundingMode;

@end

Then in your Swift code replace everywhere: NSDecimalRound(&result, &number, scale, roundingMode) with DecimalRoundFix.round(&result, number: &number, scale: scale, roundingMode:roundingMode).

This is fixed in the latest Xcode!

More symbols seem to be missing in addition to just NSDecimal.

I'm getting the following crash when building with Xcode 16.0 (16A242d) to an iPhone running iOS 16.7.8.

dyld[75345]: Symbol not found: _NSURLDirectoryEntryCountKey
  Referenced from: <UUID> /private/var/containers/Bundle/Application/<UUID>/MyApp.app/MyApp.debug.dylib
  Expected in:     <UUID> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation

Commenting out all code using URLResourceValues.directoryEntryCountKey fixes the build and it launches successfully on the iPhone.

That’s a slightly different wrinkle. According to the docs, NSURLDirectoryEntryCountKey was new in iOS 17, so the compiler should’ve added a weak import for that symbol. And indeed that’s that I see when I create a new app that uses it:

% nm -m Test763642.app/Test763642.debug.dylib | grep NSURLDirectoryEntryCountKey
    (undefined) weak external _NSURLDirectoryEntryCountKey (from CoreFoundation)

My app’s deployment target is set to iOS 16 and my code looks like this

if #available(iOS 17.0, *) {
    print(URLResourceKey.directoryEntryCountKey)
} else {
    // Fallback on earlier versions
}

I ran my app on an iOS 16 device (iOS 16.7.8) and it launched just fine.

I suspect there’s something about your main project that’s causing the symbol to not be marked as a weak import. Try reproducing my test in a small test project and see what you get

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Crash on launch from all TestFlight builds, but when loading the app from Xcode
 
 
Q