SettingsBundleBuilder provides an easy way to produce settings bundles for iOS apps with a SwiftUI-like syntax.
Motivation
Working with property list files is a nuisance - you might not know what key/values are required for each settings item. With a SwiftUI style syntax, there is the benefit of type-checking and autocomplete. You can then be told exactly where the errors are in your plist without running the app and inspecting it.
Additionally, property lists can become difficult to work with for large setting screens. Again, a SwiftUI style syntax drastically improves this because it is easier to see the hierachal view structure.
Quick Start
Add a new Swift Package locally to your existing project.
Mark the Swift Package as executable by changing the Package.swift file to list the following instead of a library:
Run the Swift Package (⌘ + R) which will generate the settings bundle and open it in a Finder window. Drag this into your main project and you’re good to go!
Example Usage
Below is an example of a complex settings bundle using every SettingsBundleItem in the package:
There are many items provided in this package, each used to present a particular cell on the settings page.
Some of the frequent properties used by the items are below:
title - the string displayed to the user describing this setting/item
key - the UserDefaults key to change when this setting is changed
defaultValue - the value to provide to the UI when the key cannot be found in UserDefaults
There are many other parameters but these are fairly straightforward and documented using Xcode’s documentation tool. To access documentation, use command + click on a method/type.
The full list of items are:
Group
MultiValue
Page
RadioGroup
Slider
Text
TextField
Toggle
MultiValue, RadioGroup and Text
The MultiValue, RadioGroup and Text items use a different strategy to display text to the user. To do so, they use these properties:
possibleValues - the possible string values that could be stored in UserDefaults for the provided key
readableValues - a mapping of the possibleValues to human readable versions; this array should be in the same order as the possible values
For MultiValue and RadioGroup, this is used to display the list of values a user can choose from.
For Text, this is used to display dynamic content based on a value in UserDefaults.
Groups
A Group offers a way to organise multiple items. Optionally provide header and footer text.
Note that groups cannot be nested inside one another. The RadioGroup item acts like a group in the UI so cannot be placed inside a Group.
NOTE: If an non-group item is placed at the root level after a Group, it will appear in the group in the UI due to the formatting of a .plist settings bundle. To avoid this, embed this item in a group.
Pages
A Page can offer nested pages of settings. Simply provide the title and content.
To split code apart for clarity, use something similar to the following:
SettingsBundleBuilder
SettingsBundleBuilder
provides an easy way to produce settings bundles for iOS apps with a SwiftUI-like syntax.Motivation
Working with property list files is a nuisance - you might not know what key/values are required for each settings item. With a SwiftUI style syntax, there is the benefit of type-checking and autocomplete. You can then be told exactly where the errors are in your
plist
without running the app and inspecting it.Additionally, property lists can become difficult to work with for large setting screens. Again, a SwiftUI style syntax drastically improves this because it is easier to see the hierachal view structure.
Quick Start
Add a new Swift Package locally to your existing project.
Mark the Swift Package as executable by changing the
Package.swift
file to list the following instead of a library:SettingsBundleBuilder
as a dependency, by adding:main.swift
, create your settings bundle using themakeSettingsBundle
method. A quick example:⌘ + R
) which will generate the settings bundle and open it in a Finder window. Drag this into your main project and you’re good to go!Example Usage
Below is an example of a complex settings bundle using every
SettingsBundleItem
in the package:SettingsBundleItem
There are many items provided in this package, each used to present a particular cell on the settings page.
Some of the frequent properties used by the items are below:
title
- the string displayed to the user describing this setting/itemkey
- theUserDefaults
key to change when this setting is changeddefaultValue
- the value to provide to the UI when the key cannot be found inUserDefaults
The full list of items are:
Group
MultiValue
Page
RadioGroup
Slider
Text
TextField
Toggle
MultiValue, RadioGroup and Text
The
MultiValue
,RadioGroup
andText
items use a different strategy to display text to the user. To do so, they use these properties:possibleValues
- the possible string values that could be stored inUserDefaults
for the provided keyreadableValues
- a mapping of thepossibleValues
to human readable versions; this array should be in the same order as the possible valuesFor
MultiValue
andRadioGroup
, this is used to display the list of values a user can choose from.For
Text
, this is used to display dynamic content based on a value inUserDefaults
.Groups
A
Group
offers a way to organise multiple items. Optionally provide header and footer text.Note that groups cannot be nested inside one another. The
RadioGroup
item acts like a group in the UI so cannot be placed inside aGroup
.NOTE: If an non-group item is placed at the root level after a
Group
, it will appear in the group in the UI due to the formatting of a.plist
settings bundle. To avoid this, embed this item in a group.Pages
A
Page
can offer nested pages of settings. Simply provide thetitle
andcontent
.To split code apart for clarity, use something similar to the following:
Future Improvements
Future improvements I may make to this package in the future include:
SupportedUserInterfaceIdioms
to change settings bundle for iOS and iPadOSMinimumValueImage
andMaximumValueImage
forSlider
Legal
Please see LICENSE.md for license details.