A utility library for creating long declaration contexts like SwiftUI.
SwiftyDeclarationProvider support Swift Package Manager. You can use following steps to add this library to your project.
- Open your Xcode project.
- Click File -> Add Package Denpendenicies...
- Paste
https://github.com/AreroKetahi/SwiftyDeclarationProvider
to search fields. - Change Dependency Rule to
Up to Next Minor Version
. - Click "Copy Dependency" to add this library to your project.
- SwiftyDeclarationProvider use
DeclarationProvider
for namespace, after using that, please addimport DeclarationProvider
at the top of the codes.
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")
}
}
}
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.
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)
}
You can build documentation after download by using control+shift+command+D
.
There everything on it.