BlockFactory

@objcMembers public class BlockFactory : NSObject

Factory for instantiating new Block instances by name.

Block builders can be loaded into the factory by:

  • Loading default files containing JSON block definitions. The contents of these files are predefined by the Blockly library.
  • Loading custom files containing JSON block definitions.
  • Manually creating a BlockBuilder for a specific block name and assigning it to the factory.
  • Loads block builders from a list of default files containing JSON block definitions. The contents of these files are predefined by the Blockly library.

    Note

    This method will overwrite any existing block builders that contain the same name.

    Declaration

    Swift

    public func load(fromDefaultFiles defaultFiles: BlockJSONFile)
  • Loads block builders from a list of files containing JSON block definitions.

    Note

    This method will overwrite any existing block builders that contain the same name.

    Throws

    BlocklyError: Thrown if a JSON file could not be found or read, or if the JSON contains invalid block definition(s).

    Declaration

    Swift

    public func load(fromJSONPaths jsonPaths: [String], bundle: Bundle? = nil) throws
  • Sets the block builder to use when making new blocks of a given name.

    Note

    This method automatically sets blockBuilder.name to match the given name.

    Declaration

    Swift

    public func setBlockBuilder(_ blockBuilder: BlockBuilder, forName name: String)
  • Returns the block builder that is being used for given block name.

    Declaration

    Swift

    public func blockBuilder(forName name: String) -> BlockBuilder?

    Return Value

    The BlockBuilder matching the given name or nil if no block builder could be found.

  • Updates self.mutators from a dictionary of mutators. If a mutator already exists in self.mutators for a given name, that value is overwritten by the one supplied by mutators. These mutators are associated with block builders when they are loaded from JSON files.

    Declaration

    Swift

    public func updateMutators(_ mutators: [String: Mutator])
  • Updates self.blockExtensions from a dictionary of given block extensions. If an extension already exists in self.blockExtensions for a given name, that value is overwritten by the one supplied by extensions. These extensions are associated with block builders when they are loaded from JSON files.

    Declaration

    Swift

    public func updateBlockExtensions(_ blockExtensions: [String: BlockExtension])
  • Creates and returns a new Block with the given name.

    Throws

    BlocklyError: Occurs if the block builder for the given name could not be found or if the block builder is missing any required pieces.

    Declaration

    Swift

    public func makeBlock(name: String) throws -> Block

    Return Value

    A new Block.

  • Creates and returns a new Block with the given name.

    Throws

    BlocklyError: Occurs if the block builder for the given name could not be found or if the block builder is missing any required pieces.

    Declaration

    Swift

    public func makeBlock(name: String, shadow: Bool, uuid: String? = nil) throws -> Block

    Return Value

    A new Block.