https://github.com/digipolitan/swift-code-writer
https://github.com/digipolitan/swift-code-writer
builder source-code swift writer
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/digipolitan/swift-code-writer
- Owner: Digipolitan
- License: bsd-3-clause
- Created: 2017-08-16T08:46:00.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-06T21:38:09.000Z (over 7 years ago)
- Last Synced: 2025-03-06T14:31:32.582Z (over 1 year ago)
- Topics: builder, source-code, swift, writer
- Language: Swift
- Size: 60.5 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
SwiftCodeWriter
=================================
[](https://developer.apple.com/swift/)
[](https://swift.org/package-manager/)
[](http://twitter.com/Digipolitan)
Library to write swift source code
## Installation
### SPM
To install SwiftCodeWriter with SwiftPackageManager, add the following lines to your `Package.swift`.
```swift
let package = Package(
name: "XXX",
products: [
.library(
name: "XXX",
targets: ["XXX"]),
],
dependencies: [
.package(url: "https://github.com/Digipolitan/swift-code-writer.git", from: "1.0.0")
],
targets: [
.target(
name: "XXX",
dependencies: ["SwiftCodeWriter"])
]
)
```
## The Basics
The you must create a file description that represent the swift output file
```swift
let fileDescription = FileDescription()
```
A file description can contains :
- classes `[ClassDescription]`
- enums `[EnumDescription]`
- protocols `[ProtocolDescription]`
- extensions `[ExtensionDescription]`
- methods `[MethodDescription]`
- properties `[PropertyDescription]`
- documentation
The following example will show how to register a structure inside the file description
```swift
// Add a User struct with 2 properties
var cd = ClassDescription(name: "User", options: .init(visibility: .public, isReferenceType: true))
cd.properties.append(.init(name: "lastName", type: "String?"))
cd.properties.append(.init(name: "firstName", type: "String?"))
fileDescription.classes.append(cd)
```
After that use the FileWriter to transform the given FileDescription to string as follow
```swift
let res = FileWriter.default.write(description: fileDescription)
```
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details!
This project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md).
By participating, you are expected to uphold this code. Please report
unacceptable behavior to [contact@digipolitan.com](mailto:contact@digipolitan.com).
## License
SwiftCodeWriter is licensed under the [BSD 3-Clause license](LICENSE).