Workspace

@objcMembers open class Workspace : NSObject

Data structure that contains Block instances.

  • A unique identifier used to identify this workspace for its lifetime

    Declaration

    Swift

    public let uuid: String
  • The maximum number of blocks that this workspace may contain. If this value is set to nil, no maximum limit is enforced.

    Declaration

    Swift

    public let maxBlocks: Int?
  • The maximum number of blocks that can be currently added to the workspace. If this value is nil, no maximum limit is being enforced.

    Declaration

    Swift

    public var remainingCapacity: Int?
  • Dictionary mapping all Block instances in this workspace to their uuid value

    Declaration

    Swift

    public fileprivate(set) var allBlocks = [String: Block]()
  • Flag indicating if this workspace is set to read-only

    Declaration

    Swift

    public var readOnly: Bool = false
  • The listener for events that occur in this workspace

    Declaration

    Swift

    public var listeners = WeakSet<WorkspaceListener>()
  • The layout associated with this workspace

    Declaration

    Swift

    public weak var layout: WorkspaceLayout?
  • Creates a Workspace, with no maximum capacity.

    Declaration

    Swift

    public override init()
  • Creates a Workspace, specifying a maximum capacity.

    Declaration

    Swift

    public init(uuid: String? = nil, maxBlocks: Int? = nil)
  • Returns a list of all blocks in the workspace whose topLevel property is true.

    Declaration

    Swift

    open func topLevelBlocks() -> [Block]

    Return Value

    A list of all top-level blocks in the workspace.

  • Adds a block and all of its connected blocks to the workspace.

    Throws

    BlocklyError: Thrown if one of the blocks uses a uuid that is already being used by another block in the workspace or if adding the new set of blocks would exceed the maximum amount allowed.

    Declaration

    Swift

    open func addBlockTree(_ rootBlock: Block) throws
  • Adds a list of blocks and all of their connected blocks to the workspace.

    Throws

    BlocklyError: Thrown if one of the blocks uses a uuid that is already being used by another block in the workspace or if adding the new list of blocks would exceed the maximum amount allowed.

    Declaration

    Swift

    open func addBlockTrees(_ rootBlocks: [Block]) throws
  • Removes a given block and all of its connected child blocks from the workspace.

    Throws

    BlocklyError: Thrown if the tree of blocks could not be removed from the workspace.

    Declaration

    Swift

    open func removeBlockTree(_ rootBlock: Block) throws
  • Removes a given list of blocks and all of their connected child blocks from the workspace.

    Throws

    BlocklyError: Thrown if the list of blocks could not be removed from the workspace.

    Declaration

    Swift

    open func removeBlockTrees(_ rootBlocks: [Block]) throws
  • Deep copies a block and adds all of the copied blocks into the workspace.

    Throws

    BlocklyError: Thrown if the block could not be copied

    Declaration

    Swift

    open func copyBlockTree(
        _ rootBlock: Block, editable: Bool, position: WorkspacePoint) throws -> Block

    Return Value

    The root block that was copied

  • Returns if this block has been added to the workspace.

    Declaration

    Swift

    open func containsBlock(_ block: Block) -> Bool

    Return Value

    true if this block has been added to the workspace. false otherwise.

  • For each top-level block tree in the workspace, deactivates those that contain blocks exceeding a given threshold and activates those that don’t exceed the given threshold.

    Note

    This method should only be called for toolbox categories or trash cans. It is not intended to be used for the main editing workspace.

    Declaration

    Swift

    open func deactivateBlockTrees(forGroupsGreaterThan threshold: Int)
  • Finds all blocks that have a field using a specific variable name.

    • param name: The name to search

    Declaration

    Swift

    public func allVariableBlocks(forName name: String) -> [Block]
  • Loads blocks from an XML string into the workspace.

    Throws

    BlocklyError: Occurs if there is a problem parsing the xml (eg. insufficient data, malformed data, or contradictory data).

    Declaration

    Swift

    public func loadBlocks(fromXMLString xmlString: String, factory: BlockFactory) throws
  • Loads blocks from an XML object into the workspace.

    Throws

    BlocklyError: Occurs if there is a problem parsing the xml (eg. insufficient data, malformed data, or contradictory data).

    Declaration

    Swift

    public func loadBlocks(fromXML xml: AEXMLElement, factory: BlockFactory) throws
  • Returns an XML string representing the current state of this workspace.

    Throws

    BlocklyError: Thrown if there was an error serializing any of the blocks in the workspace.

    Declaration

    Swift

    public func toXML() throws -> String

    Return Value

    The XML string.