Field

@objcMembers open class Field: NSObject

Input field. Used for editable titles, variables, etc. This is an abstract class that defines the UI on the block. Actual instances would be FieldLabel, FieldDropdown, etc.

  • The name of the field

    Declaration

    Swift

    public let name: String
  • The input that owns this field

    Declaration

    Swift

    public weak var sourceInput: Input?
  • The layout associated with this field.

    Declaration

    Swift

    public weak var layout: FieldLayout?
  • Listeners for events that occur on this field

    Declaration

    Swift

    public var listeners = WeakSet<FieldListener>()
  • Flag indicating if this field can be edited

    Declaration

    Swift

    public var editable: Bool = true
  • Returns a copy of this field.

    Note

    This method needs to be implemented by a subclass of Field. Results are undefined if a Field subclass does not implement this method.

    Declaration

    Swift

    open func copyField() -> Field

    Return Value

    A copy of this field.

  • Sets the native value of this field from a serialized text value.

    Throws

    BlocklyError: Thrown if the serialized text value could not be converted into the field’s native value.

    Note

    This method needs to be implemented by a subclass of Field. Results are undefined if a Field subclass does not implement this method.

    Declaration

    Swift

    open func setValueFromSerializedText(_ text: String) throws
  • Converts the native value of this field to a serialized text value.

    Throws

    BlocklyError: Thrown if the field’s native value could not be serialized into a text value.

    Note

    This method needs to be implemented by a subclass of Field. Results are undefined if a Field subclass does not implement this method.

    Declaration

    Swift

    open func serializedText() throws -> String?

    Return Value

    The serialized text value. If the field cannot be serialized, nil is returned instead.

  • A convenience method that should be called inside the didSet { ... } block of instance properties from Field subclasses.

    If property != oldValue, this method will automatically call notifyDidUpdateField(). If property == oldValue, nothing happens.

    Usage:

    var someString: String {
      didSet { didSetProperty(someString, oldValue) }
    }
    

    Declaration

    Swift

    open func didSetProperty<T: Equatable>(_ property: T, _ oldValue: T) -> Bool

    Return Value

    true if property is now different than oldValue. false otherwise.

  • A convenience method that should be called inside the didSet { ... } block of instance properties from Field subclasses.

    If property != oldValue, this method will automatically call notifyDidUpdateField(). If property == oldValue, nothing happens.

    Usage:

    var someNullableString: String? {
      didSet { didSetProperty(someNullableString, oldValue) }
    }
    

    Declaration

    Swift

    open func didSetProperty<T: Equatable>(_ property: T?, _ oldValue: T?) -> Bool

    Return Value

    true if property is now different than oldValue. false otherwise.

  • Sends a notification to self.listeners that this field has been updated.

    Declaration

    Swift

    public func notifyDidUpdateField()
  • Manages the registration of fields.

    This class is designed as a singleton instance, accessible via Field.JSONRegistry.shared.

    Declaration

    Swift

    @objcMembers public final class JSONRegistry: NSObject