Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Automatic Extraction in String Catalog

Is there a way to disable automatic extraction when using String Catalog?

The following code block invokes an initializer with LocalizedStringKey and not with StringProtocol.

Text("Hello World!")

Text has a workaround for this in a form of init(verbatim:). But the same functionality doesn't exist for other UI elements—Button, TextField, etc.

I was looking for more global solution. But using String("Hello World!") or "Hello World!".toString everywhere seems excessive.

like image 483
Vakho Avatar asked Oct 20 '25 06:10

Vakho


2 Answers

Yes you can do so by updating the following build settings in your target:

  • Localized String SwiftUI Support (LOCALIZED_STRING_SWIFTUI_SUPPORT): NO
  • Use Compiler to Extract Swift Strings (SWIFT_EMIT_LOC_STRINGS): NO
like image 130
liamnichols Avatar answered Oct 22 '25 22:10

liamnichols


💡 Compiler extracts LocalizedStringKey from some SwiftUI initializers.

✅ You can force it use the String overload instead to prevent automatic extraction:

Text(String("Hello World!"))

Button(String("Goodbye World!")) { }

// or

let string = "What in the World!"
Text(string)
like image 31
Mojtaba Hosseini Avatar answered Oct 22 '25 21:10

Mojtaba Hosseini