Search code examples
swiftcrashnslocalizedstringios16

Static NSLocalizedString causes "one-time initialization function" crash only on iOS16


We usually define NSLocalizedString as static variables in a String extension such as:

extension String {
    static let text = NSLocalizedString("text_key", tableName: "Translations", value: "text", comment:"")
}

Then we have some classes that uses this constant strings to initialize some variables such like:

class DummyClass {
   var randomText: String? = .text
}

Having said that, that approach worked fine until now. When iOS16 was released, we started seeing a lot of crashes related to this piece of code (only iOS16 sessions). Although, we can not reproduce this locally to investigate the causes, we know the crash happens on app startup.

Crash signature is one-time initialization function for X, where X is the name of the string constant, followed by EXC_BAD_ACCESS.

Anyone can please advice what changed on iOS16 in regards to this? Did anyone face the a similar situation? How to fix the crash?


Solution

  • faced the same problem. did you use On-demand resources for your project? highly suspicious for ODR.