CodeGeneratorService

@objcMembers public final class CodeGeneratorService: NSObject

Service for generating code from a workspace.

For details on how to use this class, see: https://developers.google.com/blockly/guides/configure/ios/code-generators

  • Closure that is called when code has been generated for a request.

    Declaration

    Swift

    public typealias CompletionClosure = (_ requestUUID: String, _ code: String) -> Void
  • Closure that is called when an error occurs during a code generation request.

    Declaration

    Swift

    public typealias ErrorClosure = (_ requestUUID: String, _ error: String) -> Void
  • Creates a code generator service.

    Declaration

    Swift

    public convenience init(jsCoreDependencies: [String])
  • Creates a code generator service.

    Declaration

    Swift

    public init(jsCoreDependencies: [String], bundle: Bundle)
  • Sets the code generator service request builder to be used for code generation.

    Declaration

    Swift

    public func setRequestBuilder(_ builder: CodeGeneratorServiceRequestBuilder,
        shouldCache: Bool)
  • Requests that code be generated from a given workspace.

    Note

    setRequestBuilder(:shouldCache:) must be called prior to calling this method.

    Throws

    BlocklyError: Occurs if no request builder has not been set prior to calling this method or if workspace could not be serialized into XML.

    Declaration

    Swift

    public func generateCode(forWorkspace workspace: Workspace,
                               onCompletion: CompletionClosure? = nil,
                               onError: ErrorClosure? = nil) throws -> String

    Return Value

    A UUID representing this particular request.

  • Requests that code be generated from given workspace XML.

    Note

    setRequestBuilder(:shouldCache:) must be called prior to calling this method.

    Throws

    BlocklyError: Occurs if no request builder has not been set prior to calling this method.

    Declaration

    Swift

    public func generateCode(forWorkspaceXML xml: String,
                               onCompletion: CompletionClosure? = nil,
                               onError: ErrorClosure? = nil) throws -> String

    Return Value

    A UUID representing this particular request.

  • Cancels code generation for a given request.

    Declaration

    Swift

    public func cancelRequest(uuid: String)
  • Cancels all pending code generation requests.

    Declaration

    Swift

    public func cancelAllRequests()