Last active
June 29, 2018 14:16
-
-
Save regularberry/1bdf0038f043c0793c24bffcecb24b23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let structBuilder = StructSpec.builder(for: "TestStruct") | |
let fieldBuilder = FieldSpec.builder(for: "myField", type: .StringType, construct: nil) | |
structBuilder.add(field: fieldBuilder.build()) | |
let methodBuilder = MethodSpec.builder(for: "doTheThing") | |
methodBuilder.add(modifier: .Public) | |
let code = """ | |
print("I'm doing the thing!") | |
""" | |
methodBuilder.add(codeBlock: code.toCodeBlock()) | |
structBuilder.add(method: methodBuilder.build()) | |
let poet = PoetFile(list: [structBuilder.build()], generatorInfo: nil) | |
print(poet.fileContents) | |
/// OUTPUT | |
----------- | |
// | |
// TestStruct.swift | |
// | |
// Contains: | |
// struct TestStruct | |
// | |
// Generated by SwiftPoet on 6/29/18 | |
// | |
struct TestStruct { | |
let myField: String | |
public func doTheThing() { | |
print("I'm doing the thing!") | |
} | |
/** | |
:param: myField | |
*/ | |
internal init(myField: String) { | |
self.myField = myField | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment