Connection

@objcMembers public final class Connection : NSObject

Component used to create a connection between two Block instances.

  • Represents all possible types of connections.

    Declaration

    Swift

    public enum ConnectionType: Int
  • Represents a combination of result codes when trying to connect two connections

    Declaration

    Swift

    public struct CheckResult: OptionSet
  • A globally unique identifier

    Declaration

    Swift

    public let uuid: String
  • The connection type

    Declaration

    Swift

    public let type: ConnectionType
  • The block that holds this connection

    Declaration

    Swift

    public internal(set) weak var sourceBlock: Block?
  • If this connection belongs to a value or statement input, this is its source

    Declaration

    Swift

    public internal(set) weak var sourceInput: Input?
  • The position of this connection in the workspace. NOTE: While this value should be stored in a Layout subclass, it’s more efficient to simply store the absolute position here since it’s the only relevant property needed.

    Declaration

    Swift

    public fileprivate(set) var position: WorkspacePoint = WorkspacePoint.zero
  • The connection that this one is connected to

    Declaration

    Swift

    public fileprivate(set) weak var targetConnection: Connection?
  • The shadow connection that this one is connected to

    Declaration

    Swift

    public fileprivate(set) weak var shadowConnection: Connection?
  • The source block of self.targetConnection

    Declaration

    Swift

    public var targetBlock: Block?
  • The source block of self.shadowConnection

    Declaration

    Swift

    public var shadowBlock: Block?
  • true if self.targetConnection is non-nil. false otherwise.

    Declaration

    Swift

    public var connected: Bool
  • true if self.shadowConnection is non-nil. false otherwise.

    Declaration

    Swift

    public var shadowConnected: Bool
  • The set of checks for this connection. Two Connections may be connected if one of them supports any connection (when this is null) or if they share at least one common check value. For example, {Number, Integer, MyValueType} and {AnotherType, Integer} would be valid since they share Integer as a check.

    Declaration

    Swift

    public var typeChecks: [String]?
  • Whether the connection has high priority in the context of bumping connections away.

    Declaration

    Swift

    public var highPriority: Bool
  • Connection position delegate

    Declaration

    Swift

    public final weak var positionDelegate: ConnectionPositionDelegate?
  • This value is true if this connection is an inferior connection (ie. .outputValue or .previousStatement). Otherwise, this value is false.

    Declaration

    Swift

    public var isInferior: Bool
  • Creates a Connection.

    Declaration

    Swift

    public init(type: Connection.ConnectionType, sourceInput: Input? = nil)
  • Sets self.targetConnection to a given connection, and vice-versa.

    Throws

    BlocklyError: Thrown if the connection could not be made, with error code .ConnectionInvalid

    Declaration

    Swift

    public func connectTo(_ connection: Connection?) throws
  • Sets self.shadowConnection to a given connection, and vice-versa.

    Throws

    BlocklyError: Thrown if the connection could not be made, with error code .ConnectionInvalid

    Declaration

    Swift

    public func connectShadowTo(_ connection: Connection?) throws
  • Removes the connection between this and self.targetConnection. If self.targetConnection is nil, this method does nothing.

    Declaration

    Swift

    public func disconnect()
  • Removes the connection between this and self.shadowConnection. If self.shadowConnection is nil, this method does nothing.

    Declaration

    Swift

    public func disconnectShadow()
  • Check if this can be connected to the target connection.

    Declaration

    Swift

    public func canConnectTo(_ target: Connection) -> Bool

    Return Value

    True if the target can be connected, false otherwise.

  • Check if a given connection can be connected to the target connection, with a specific set of reasons.

    Declaration

    Swift

    public func canConnectWithReasonTo(_ target: Connection?) -> CheckResult

    Return Value

    If the connection is legal, [CheckResult.Value.CanConnect] is returned. Otherwise, a set of all error codes are returned.

  • Check if a given connection can be connected to the shadow connection, with a specific set of reasons.

    Declaration

    Swift

    public func canConnectShadowWithReasonTo(_ shadow: Connection?) -> CheckResult

    Return Value

    If the connection is legal, [CheckResult.Value.CanConnect] is returned. Otherwise, a set of all error codes are returned.

  • Returns the distance between this connection and another connection.

    Declaration

    Swift

    public func distanceFromConnection(_ other: Connection) -> CGFloat

    Return Value

    The distance between connections.

  • Move the connection to a specific position.

    Declaration

    Swift

    public func moveToPosition(
        _ position: WorkspacePoint, withOffset offset: WorkspacePoint = WorkspacePoint.zero)