I have two apps, both made on iPad with Swift Playgrounds 4. The newer one was made with the latest release of SP4 and thus uses Swift 5.6, the other uses Swift 5.5 because it was made with a former version of SP4. iPadOS is 15.7.
Both apps make use of a Settings.bundle and both use the same code to register.
@main
struct MyApp: App {
init() {
if !UserDefaults.standard.bool(forKey: "launchedBefore") {
registerDefaultSettings()
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"]
let build = Bundle.main.infoDictionary?["CFBundleVersion"]
let versionInfo = "\(version!) (\(build!))"
UserDefaults.standard.set( versionInfo, forKey: "versionInfo")
UserDefaults.standard.set(true, forKey: "launchedBefore")
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
private func registerDefaultSettings() {
guard
let settingsBundle = Bundle.main.url(forResource: "Root.plist", withExtension: nil),
let settings = NSDictionary(contentsOf: settingsBundle),
let keyValues = settings.object(forKey: "PreferenceSpecifiers") as? [[String: AnyObject]]
else {
return
}
var defaultSettings = [String : AnyObject]()
for keyValue in keyValues {
if
let key = keyValue["Key"] as? String,
let value = keyValue["DefaultValue"] {
defaultSettings[key] = value
}
}
UserDefaults.standard.register(defaults: defaultSettings)
}
The settings of the 5.5 app appear in the Settings App whereas the settings of the 5.6 do not. If I move the Settings.bundle folder from 5.6. to 5.5, the settings for 5.6 appear in 5.5 thus the file structure and contents seem to be syntactically ok).
There was one obvious difference when setting up Settings.bundle in 5.6: SP4 requested to set defaultLocalization in Package.swift.
How do I get the 5.6 Settings.bundle to appear in the Settings App?