Functions
The following functions are available globally.
-
Creates a Fragment formatted specifically for Swift computed properties
Declaration
Swift
@inlinable public func computedPropertySpec( _ name: String, access: Access = .internal, isStatic: Bool = false, returnValue: String, @CodeBuilder _ body: () -> CodeRepresentable ) -> CodeRepresentableParameters
nameThe name of the computed property
accessThe access level of the the computed property
isStaticBool flag that determines whether or not the computed property is static
returnValueThe return value of the function
bodyFragments that represent the body of the computed property
Return Value
A GroupFragment typed as CodeRepresentable
-
Creates a Fragment formatted specifically for Swift control flow statements
Example:
fileSpec(" ") { controlFlowSpec("if word == \"That\"") { statement("print(\"Hello, \\(word)\")") } end() }renders:
if word == "That" { print("Hello, \(word)") }Declaration
Swift
@inlinable public func controlFlowSpec(_ statement: String, @CodeBuilder _ builder: () -> CodeRepresentable) -> CodeRepresentableParameters
statementString representing the logic for the control flow.
builderFragments that represent the body of the control flow.
Return Value
A MultiLineFragment typed as CodeRepresentable
-
Creates a Fragment formatted specifically for
else ifSwift control flow statementsExample:
fileSpec(" ") { controlFlowSpec("if word == \"That\"") { statement("print(\"word is That\")") } elseIfSpec("word == \"This\"") { statement("print(\"word is This\")") } end() }renders:
if word == "That" { print("word is That") } else if word == "This" { print("word is This") }Declaration
Swift
@inlinable public func elseIfSpec(_ statement: String, @CodeBuilder _ builder: () -> CodeRepresentable) -> CodeRepresentableParameters
statementString representing the Bool logic for the
else ifcontrol flow.builderFragments that represent the body of the
else ifcontrol flow.Return Value
A MultiLineFragment typed as CodeRepresentable
-
Creates a Fragment formatted specifically for
elseSwift control flow statementsExample:
fileSpec(" ") { controlFlowSpec("if word == \"That\"") { statement("print(\"word is That\")") } elseIfSpec("word == \"This\"") { statement("print(\"word is This\")") } elseSpec { statement("print(\"word is neither That or This\")") } end() }renders:
if word == "That" { print("word is That") } else if word == "This" { print("word is This") } else { print("word is neither That or This") }Declaration
Swift
@inlinable public func elseSpec(@CodeBuilder _ builder: () -> CodeRepresentable) -> CodeRepresentableParameters
builderFragments that represent the body of the
elsecontrol flow.Return Value
A MultiLineFragment typed as CodeRepresentable
-
Creates a Fragment formatted specifically for
guardSwift control flow statementsExample:
fileSpec(" ") { guardSpec( statements: { statement("x == 0") statement("y == 0") }, elseBlock: { statement( """ print("Bool failed") """ ) statement("return") } ) }renders:
guard x == 0, y == 0 else { print("Bool failed") return }Declaration
Swift
@inlinable public func guardSpec(@CodeBuilder statements: () -> CodeRepresentable, @CodeBuilder elseBlock: () -> CodeRepresentable) -> CodeRepresentableParameters
statementsThe Fragments that represent the
guardcontrol flow’s body.elseBlockThe Fragment that represent a
guardcontrol flow’s else block.Return Value
A GroupFragment typed as CodeRepresentable
-
Creates a Fragment formatted specifically for
doSwift control flow statementsExample:
fileSpec(" ") { doSpec { statement("let realm = try Realm()") statement("print(realm)") } end() }renders:
do { let realm = try Realm() print(realm) }Declaration
Swift
@inlinable public func doSpec(@CodeBuilder _ builder: () -> CodeRepresentable) -> CodeRepresentableParameters
builderThe Fragments that represent the
docontrol flow’s body.Return Value
A GroupFragment typed as CodeRepresentable
-
Creates a Fragment formatted specifically for
catchSwift control flow statementsExample:
fileSpec(" ") { doSpec { statement("let realm = try Realm()") statement("print(realm)") } catchSpec(statement: "let error") { statement(#"print("failed")"#) statement("print(error.localizedDescription)") } end() }renders:
do { let realm = try Realm() print(realm) } catch let error { print("failed") print(error.localziedDescription) }Declaration
Swift
@inlinable public func catchSpec(statement: String? = nil, @CodeBuilder _ builder: () -> CodeRepresentable) -> CodeRepresentableParameters
statementThe catch statement
builderThe Fragments that represent the
catchcontrol flow’s body.Return Value
A MultiLineFragment typed as CodeRepresentable
-
Create a CodeFragment formatted for documentation
Declaration
Swift
@inlinable public func documentationSpec( _ content: String, format: Documentation.Format = .singleLine, parameters: [Parameter] = [], returns returnsValue: String? = nil, tag: String? = nil ) -> CodeRepresentableParameters
contentThe content of the documentation
formatDetermines whether or not the content will use single line or multiline documentaion notation
parameters- content : The content of the documentation
- format : Determines whether or not the content will use single line or multiline documentaion notation
- returnsValue : The return value documentation
- tag : The tag link to this documentation
returnsValueThe return value documentation
tagThe tag link to this documentation
Return Value
A Documentation typed as CodeRepresentable
-
Creates a File that represents the Swift code built from the Fragments.
Declaration
Swift
@inlinable public func fileSpec(fileName: String, indent: String, @CodeBuilder _ builder: () -> CodeRepresentable) -> FileParameters
fileNameThe name of the Swift file to be created
indentWhitespace indentation used to render Swift code
builderCreates Fragments that build the String representing Swift code.
Return Value
A File instance
-
Creates a Fragment formatted specifically for Swift functions
Declaration
Swift
@inlinable public func functionSpec( _ name: String, access: Access = .internal, isStatic: Bool = false, keywords: Set<FunctionKeyword> = [], genericSignature: String? = nil, arguments: [Argument] = [], returnValue: String? = nil, @CodeBuilder _ builder: () -> CodeRepresentable ) -> CodeRepresentableParameters
nameThe name of the function
accessThe access level of the function
isStaticBool flag that determines whether or not the function is a static method
throwsErrorBool flag that determines whether or not the function throws
genericSignatureThe generic signature of the function
argumentsThe arguments of the function
returnValueThe return value of the function
builderFragments that represent the body of the function
Return Value
A GroupFragment typed as a CodeRepresentable
-
Creates a SingleLineFragment out of a String
Declaration
Swift
@inlinable public func statement(_ statement: String) -> FragmentParameters
statementThe string content of the SingleLineFragment
Return Value
A SingleLineFragment typed as a Fragment
-
Adds a line break
Declaration
Swift
@inlinable public func lineBreak() -> FragmentReturn Value
A SingleLineFragment typed as a Fragment
-
Ends scope
Declaration
Swift
@inlinable public func end() -> FragmentReturn Value
A SingleLineFragment typed as a Fragment
-
Creates a Fragment formatted specifically as an initializer.
Declaration
Swift
@inlinable public func initializerSpec( access: Access = .internal, documentation: Documentation? = nil, arguments: [Argument], throwsError: Bool, @CodeBuilder _ body: () -> CodeRepresentable ) -> CodeRepresentableParameters
accessThe access level of the initializer
documentationThe documentation of the initializer
argumentsThe arguments of the initializer
throwsErrorBool flag indicating if the initializer throws or not
bodyThe body of the initializer
Return Value
A GroupFragment typed as a CodeRepresentable
-
Creates a Fragment formatted specifically as an initializer with no custom body other than assigning arguments.
Declaration
Swift
@inlinable public func initializerSpec( access: Access = .internal, documentation: Documentation? = nil, arguments: [Argument], throwsError: Bool = false ) -> CodeRepresentableParameters
accessThe access level of the initializer
documentationThe documentation of the initializer
argumentsThe arguments of the initializer
throwsErrorBool flag indicating if the initializer throws or not
Return Value
A GroupFragment typed as a CodeRepresentable
-
Transforms the String into SingleLineFragments and wraps the array in a Code.fragments enum case.
The content is separated by a newline, removes trailing whitespace and transformed into an array of SingleFragments
Declaration
Swift
@inlinable public func rawSpec(_ content: String) -> CodeRepresentableParameters
contentA String that represents Swift code.
Return Value
A Code.fragments instance as CodeRepresentable
-
Creates a Fragment formatted specifically for defining a Swift type
Declaration
Swift
@inlinable public func typeSpec( _ name: String, access: Access = .internal, type: DataType, inheritingFrom parents: [String] = [], @CodeBuilder _ builder: () -> CodeRepresentable = { Code.none } ) -> CodeRepresentableParameters
nameThe name of the type being defined
accessThe access level of the type
typeDetermines whether the type being defined is a class, enum or struct
parentsThe parent class/protocols the type inherits or conforms to
builderFragments that represent the body of the type’s definition
Return Value
A GroupFragment typed as a CodeRepresentable
-
Creates a Fragment formatted specifically for defining a Swift class type
Declaration
Swift
@inlinable public func classSpec(_ name: String, access: Access = .internal, inheritingFrom parents: [String] = [], @CodeBuilder _ builder: () -> CodeRepresentable) -> CodeRepresentableParameters
nameThe name of the class being defined
accessThe access level of the class
parentsThe parent class/protocols the class inherits or conforms to
builderFragments that represent the body of the class’s definition
Return Value
A GroupFragment typed as a CodeRepresentable
-
Creates a Fragment formatted specifically for defining a Swift class type
Declaration
Swift
@inlinable public func structSpec(_ name: String, access: Access = .internal, inheritingFrom protocols: [String] = [], @CodeBuilder _ body: () -> CodeRepresentable) -> CodeRepresentableParameters
nameThe name of the struct being defined
accessThe access level of the struct
protocolsThe protocols the struct conforms to
bodyFragments that represent the body of the struct’s definition
Return Value
A GroupFragment typed as a CodeRepresentable
-
Creates a Fragment formatted specifically for defining a Swift enum type with either normal enum cases, associated value cases, or both
Declaration
Swift
@inlinable public func enumSpec( access: Access = .internal, enumSpec: Enum, inheritingFrom protocols: [String] = [], @CodeBuilder _ body: () -> CodeRepresentable = { Code.none } ) -> CodeRepresentableParameters
accessThe access level of the enum
enumSpecThe enum specification
protocolsThe protocols the enum conforms to
bodyFragments that represent the body of the enum’s definition. This should not contain cases.
Return Value
A GroupFragment typed as a CodeRepresentable
-
Creates a Fragment formatted specifically for defining a Swift raw value enum
Declaration
Swift
@inlinable public func rawValueEnumSpec<T>( access: Access = .internal, enumSpec: RawValueEnum<T>, inheritingFrom protocols: [String] = [], @CodeBuilder _ body: () -> CodeRepresentable = { Code.none } ) -> CodeRepresentableParameters
accessThe access level of the enum
enumSpecThe RawValueEnum specification
protocolsThe protocols the enum conforms to
bodyFragments that represent the body of the enum’s definition. This should not contain cases.
Return Value
A GroupFragment typed as a CodeRepresentable
View on GitHub
Install in Dash
Functions Reference