Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fcanas/tokenfield
SwiftUI wrapper for NSTokenField
https://github.com/fcanas/tokenfield
macos swift swift-package swift-package-manager swiftui swiftui-components
Last synced: 3 months ago
JSON representation
SwiftUI wrapper for NSTokenField
- Host: GitHub
- URL: https://github.com/fcanas/tokenfield
- Owner: fcanas
- License: mit
- Created: 2021-09-20T18:02:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-29T01:14:05.000Z (about 3 years ago)
- Last Synced: 2023-03-30T14:14:28.531Z (almost 2 years ago)
- Topics: macos, swift, swift-package, swift-package-manager, swiftui, swiftui-components
- Language: Swift
- Homepage:
- Size: 10.7 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TokenField
A SwiftUI wrapper for `NSTokenField`
```swift
struct MyToken {
var title: String
}struct TestView: View {
@State var tokens: [MyToken]
var body: some View {
VStack {
TokenField($tokens, { $0.title })
}
}
}
````TokenField` takes a `Binding` to a `RandomAccessCollection` of
elements to use as its tokens. When the token type does not conform
to `StringProtocol`, it also requires a closure to convert tokens to
a `String`.```swift
struct TestIdentifiableStringsView: View {
@State var tokens: [String]
var body: some View {
VStack {
TokenField($tokens)
}
}
}
````FormTokenField` can be used within a `Form` view and be given a
label that will align with standard `Form` labels.```swift
struct TestFormsView: View {
@State var tokens: [MyToken]
@State var strings: [String]
var body: some View {
Form {
FormTokenField(title:"Tokens", $tokens, { $0.title })
FormTokenField({ Text("Tokens") }, $strings)
}
}
}
```