Skip to content

Instantly share code, notes, and snippets.

@regularberry
Last active June 29, 2018 14:16
Show Gist options
  • Save regularberry/1bdf0038f043c0793c24bffcecb24b23 to your computer and use it in GitHub Desktop.
Save regularberry/1bdf0038f043c0793c24bffcecb24b23 to your computer and use it in GitHub Desktop.
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