2024 App ServicesSwiftUI & UI Frameworks
WWDC24 · 17 min · App Services / SwiftUI & UI Frameworks
Build multilingual-ready apps
Ensure your app works properly and effectively for multilingual users. Learn best practices for text input, display, search, and formatting. Get details on typing in multiple languages without switching between keyboards. And find out how the latest advances in the String Catalog can make localization even easier.
Watch at developer.apple.com ↗Chapters
Code shown on screen · 13 snippets
Specify textInputContextIdentifier
override var textInputContextIdentifier: String? {
uniqueID
} Place a view directly above the keyboard
textView.inputAccessoryView = viewAboveKeyboard Use keyboardLayoutGuide to adapt to keyboard
view.keyboardLayoutGuide.topAnchor.constraint(equalToSystemSpacingBelow: textView.bottomAnchor, multiplier: 1.0).isActive = true Check for marked text before modifying
if textView.markedTextRange.empty {
// Perform actions involving editing text
} Use localizedStandardRange when searching
let range = text.localizedStandardRange(of: search) Use color differences to highlight text
attributedString[range].foregroundColor = highlightColor Text Styles
// Text Styles
// SwiftUI
Text("Hello, world!") // uses .body Text Style by default
Text("Hello, world!").font(.title)
// UIKit
let label = UILabel()
label.text = "Hello, world!"
label.font = UIFont.preferredFont(forTextStyle: .body)
// AppKit
let textField = NSTextField(labelWithString: "Hello, world!")
textField.font = NSFont.preferredFont(forTextStyle: .body)
// Keep clipsToBounds off
clipsToBounds = false Typesetting language
// Typesetting language
// SwiftUI
Text(verbatim: "Hello, world!").typesettingLanguage(.init(languageCode: .english))
// UIKit
let label = UILabel()
label.text = "Hello, world!"
label.traitOverrides.typesettingLanguage = Locale.Language(languageCode: .english) Formatting names
// Formatting names
let nameComponents = PersonNameComponents
(givenName: "瑗珺", familyName: "汪", nickname: "珺珺")
// Short Name (respects settings like “Prefer Nicknames”)
let shortName =
nameComponents.formatted(.name(style: .short)) // 珺珺
// Abbreviated Name (can be used for monograms)
let monogram =
nameComponents.formatted(.name(style: .abbreviated)) // 汪 Examples of personalizing text
"^[Nuestro %@](inflect: true) está ^[hecho](agreeWithArgument: 1) de %@."
"अगर आप पहुँच नहीं ^[पाते हैं](inflect: true)"
"예: ‘^[%@을](inflect: true) 켤 때’" Format numbers using Text
Text("\(numberOfDays)-day forecast") Format numbers using AttributedString
AttributedString(localized: "10-day forecast")
AttributedString(localized: "0.5× zoom") Launch to your app’s settings
// Launch to your app’s settings
if let url =
URL(string: UIApplication.openSettingsURLString) {
await UIApplication.shared.open(url)
} Resources
Related sessions
-
15 min -
41 min -
15 min -
18 min -
32 min -
17 min