I have a Swift Package that contains an Objective-C target. The target contains Objective-C literals but unfortunately the compiler says "Initializer element is not a compile-time constant", what am I doing wrong?
Based on the error triggering in the upper half, I take it that objc_array_literals
is on.
My target definition looks like:
.target(
name: "MyTarget",
path: "Sources/MySourcesObjC",
publicHeadersPath: "include",
cxxSettings: [
.unsafeFlags("-fobjc-constant-literals")
]
),
I believe Objective-C literals are enabled since a long time but I still tried passing in the -fobjc-constant-literals
flag and no luck.
To be clear I'm not interested in a run-time initialization, I really want it to be compile time. Does anyone know what I can do?
I believe that this feature is only supported if your deployment target is macOS 11 or later. So, to get this working I had to add this to my Package.swift
:
platforms: [.macOS(.v11)],
Once I did that, I didn’t to manually add -fobjc-constant-literals
via the cSettings
parameter.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"