RadioButton is the missing SwiftUI Radio Button view. It uses the same approach as SwiftUI's Picker radioGroup style only available on macOS.
✅ macOS 10.15+
✅ Xcode 11.0
✅ Swift 5+
✅ iOS 14+
✅ tvOS 14+
✅ watchOS 7+
RadioButton is available via Swift Package Manager.
Using Xcode 11, go to File -> Swift Packages -> Add Package Dependency and enter https://github.com/lukluca/RadioButton
or add manually the dependency
dependencies: [
.package(url: "https://github.com/lukluca/RadioButton", from: "1.1.0")
]It's very simple to use RadioButton, expecially with Swift's enum type:
enum City: String, CaseIterable, Identifiable {
case milano
case roma
case palermo
var id: RawValue {
rawValue
}
}
struct ContentView: View {
@State private var city = City.milano
var body: some View {
RadioButton(title: "Cities:",
itemTitle: \.rawValue,
isSelected: $city)
}
}It's a requirement that your model must implement CaseIterable, Hashable and Identifiable protocol.
For furter configurations, please see RadioButtonExample folder, it contains a very simple app with all the possible scenario.
Last version is 1.1.0. This version fixes a build error on the package 😭 for watchOS. Please use this version as minimum version if your project supports watchOS.
Starting from this version, you can also customise the item's view.
Version 1.0.0 of RadioButton contains a very limited set of features, basically no particular feature 😄.
It could be extended by implementing the following tasks:
☘️ Add unit/UI tests;
☘️ Make view modifier to set common configuration (font, colors, etc);
☘️ ... many other improvements.
👨🏻🔧 Feel free to contribute to RadioButton by creating a pull request, following these guidelines:
- Fork
RadioButton - Create your feature branch
- Commit your changes, along with unit tests
- Push to the branch
- Create pull request
👨💻 @lukluca
📄 RadioButton is available under the MIT license. See the LICENSE file for more info.