Skip to content

A utility library for creating long declaration contexts like SwiftUI.

License

Notifications You must be signed in to change notification settings

AreroKetahi/SwiftyDeclarationProvider

Repository files navigation

SwiftyDeclarationProvider

A utility library for creating long declaration contexts like SwiftUI.

GitHub release (with filter) Static Badge GitHub

Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge

Initialize

Add To Project

SwiftyDeclarationProvider support Swift Package Manager. You can use following steps to add this library to your project.

  1. Open your Xcode project.
  2. Click File -> Add Package Denpendenicies...
  3. Paste https://github.com/AreroKetahi/SwiftyDeclarationProvider to search fields.
  4. Change Dependency Rule to Up to Next Minor Version.
  5. Click "Copy Dependency" to add this library to your project.

Import to codes

  • SwiftyDeclarationProvider use DeclarationProvider for namespace, after using that, please add import DeclarationProvider at the top of the codes.

Quick Setup

Directly present on View

DeclarationView can present declaration on views straightly, this is also a way to preview your declaration after export.

struct SampleView: View {
    var body: some View {
        DeclarationView {
            // add your declarations here...
          
            // This is a title
            DTitle("Sample title")
            // This is a indented group
            IndentGroup {
                // This is a text
                DText("Sample text")
                // This is a divider
                DDivider()
            }
            // This is another text
            DText("Sample text")
        }
    }
}

Present Declaration according to a JSON file or Property List

Before making a Declaration, please make JSON fiile of Property List by using JSONDecoder or PropertyListDecoder.

let jsonDecoder = JSONDecoder()
let plistDecoder = PropertyListDecoder()

let fromJson = jsonDecoder.decode(TranslatedDeclaration.self, from: data)
let fromPlist = plistDecoder.decode(TranslatedDeclaration.self, from: data)

After TranslatedDeclaration make, use DeclarationView(_ declaration: TranslatedDeclaration) to add declaration to your SwiftUI view.

You can also use DeclarationView(_ declaration: () -> TranslatedDeclaration) to make a void to make this view.

Export Declaration

You can export declaration by using TranslatedDeclaration.

TranslatedDeclaration comforms to Codable, you can export it as any format you want.

// This is an example of exporting JSON file
let declaration = Declaration(language: "en") {
    // Add your declaration here
}

do {
    let translated = try delcaration.translate()
    let encoder = JSONEncoder()
    let encoded = encoder.encode(translated)
} catch {
    print(error)
}

Documentation

You can build documentation after download by using control+shift+command+D.

There everything on it.

About

A utility library for creating long declaration contexts like SwiftUI.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages