TokenField

1.0

SwiftUI wrapper for NSTokenField
fcanas/TokenField

What's New

1.0

2021-10-29T01:14:05Z

First Release

The token fields are working, so why not call it a 1.0?

TokenField

A SwiftUI wrapper for NSTokenField

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.

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.

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)
        }
    }
}

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Oct 19 2024 11:41:12 GMT-0900 (Hawaii-Aleutian Daylight Time)