ADBoundSwitch

@IBDesignable open class ADBoundSwitch: UISwitch, ADBindable

Creates a switch that can be bound to a value from a data model that conforms to the Codable protocol when placed on a ADBoundViewController view. Use the dataPath property to specify the field from the bound data model to populate the switch from or a formula in a SQL like syntax.

Example:

// Given the following class
class Category: ADDataTable {

    enum CategoryType: String, Codable {
        case local
        case web
    }

    static var tableName = "Categories"
    static var primaryKey = "id"
    static var primaryKeyType: ADDataTableKeyType = .computedInt

    var id = 0
    var added = Date()
    var name = ""
    var description = ""
    var enabled = true
    var highlightColor = UIColor.white.toHex()
    var type: CategoryType = .local
    var icon: Data = UIImage().toData()

    required init() {

    }
}

// Bind the switch to the enabled field
mySwitch.dataPath = "enabled"
  • The name of the field from the date model used to populate the value from.

    Example:

    // Given the following class
    class Category: ADDataTable {
    
        enum CategoryType: String, Codable {
            case local
            case web
        }
    
        static var tableName = "Categories"
        static var primaryKey = "id"
        static var primaryKeyType: ADDataTableKeyType = .computedInt
    
        var id = 0
        var added = Date()
        var name = ""
        var description = ""
        var enabled = true
        var highlightColor = UIColor.white.toHex()
        var type: CategoryType = .local
        var icon: Data = UIImage().toData()
    
        required init() {
    
        }
    }
    
    // Bind the switch to the enabled field
    mySwitch.dataPath = "enabled"
    

    Remark

    The case and name of the field specified in the dataPath property must match the case and name from the data model bound to the ADBoundViewController.

    Declaration

    Swift

    @IBInspectable public var dataPath: String = ""
  • The name of the field from the date model or forumla (using SQL syntax) used to set the enabled state from.

    Example:

    // Given the following class
    class Category: ADDataTable {
    
        enum CategoryType: String, Codable {
            case local
            case web
        }
    
        static var tableName = "Categories"
        static var primaryKey = "id"
        static var primaryKeyType: ADDataTableKeyType = .computedInt
    
        var id = 0
        var added = Date()
        var name = ""
        var description = ""
        var enabled = true
        var highlightColor = UIColor.white.toHex()
        var type: CategoryType = .local
        var icon: Data = UIImage().toData()
    
        required init() {
    
        }
    }
    
    // Bind the switch to the enabled field
    mySwitch.enabledPath = "enabled"
    

    Remark

    The case and name of the field specified in the enabledPath property must match the case and name from the data model bound to the ADBoundViewController. Optionally, the value can be a forumla using a subset of the SQL syntax.

    Declaration

    Swift

    @IBInspectable public var enabledPath: String = ""
  • The name of the field from the date model or forumla (using SQL syntax) used to set the hidden state from.

    Example:

    // Given the following class
    class Category: ADDataTable {
    
        enum CategoryType: String, Codable {
            case local
            case web
        }
    
        static var tableName = "Categories"
        static var primaryKey = "id"
        static var primaryKeyType: ADDataTableKeyType = .computedInt
    
        var id = 0
        var added = Date()
        var name = ""
        var description = ""
        var enabled = true
        var quantity = 0
        var highlightColor = UIColor.white.toHex()
        var type: CategoryType = .local
        var icon: Data = UIImage().toData()
    
        required init() {
    
        }
    }
    
    // Set the hidden state based on a formula.
    mySwitch.hiddenPath = "quantity > 0"
    

    Remark

    The case and name of the field specified in the hiddenPath property must match the case and name from the data model bound to the ADBoundViewController. Optionally, the value can be a forumla using a subset of the SQL syntax.

    Declaration

    Swift

    @IBInspectable public var hiddenPath: String = ""
  • The name of the field from the date model or forumla (using SQL syntax) used to set the on tint color from.

    Example:

    // Given the following class
    class Category: ADDataTable {
    
        enum CategoryType: String, Codable {
            case local
            case web
        }
    
        static var tableName = "Categories"
        static var primaryKey = "id"
        static var primaryKeyType: ADDataTableKeyType = .computedInt
    
        var id = 0
        var added = Date()
        var name = ""
        var description = ""
        var enabled = true
        var quantity = 0
        var highlightColor = UIColor.white.toHex()
        var type: CategoryType = .local
        var icon: Data = UIImage().toData()
    
        required init() {
    
        }
    }
    
    // Set the text color based on a formula.
    mySwitch.onColorPath = "highlightColor"
    

    Remark

    The case and name of the field specified in the onColorPath property must match the case and name from the data model bound to the ADBoundViewController. Optionally, the value can be a forumla using a subset of the SQL syntax.

    Declaration

    Swift

    @IBInspectable public var onColorPath: String = ""
  • The name of the field from the date model or forumla (using SQL syntax) used to set the off tint color from.

    Example:

    // Given the following class
    class Category: ADDataTable {
    
        enum CategoryType: String, Codable {
            case local
            case web
        }
    
        static var tableName = "Categories"
        static var primaryKey = "id"
        static var primaryKeyType: ADDataTableKeyType = .computedInt
    
        var id = 0
        var added = Date()
        var name = ""
        var description = ""
        var enabled = true
        var quantity = 0
        var highlightColor = UIColor.white.toHex()
        var type: CategoryType = .local
        var icon: Data = UIImage().toData()
    
        required init() {
    
        }
    }
    
    // Set the text color based on a formula.
    mySwitch.offColorPath = "highlightColor"
    

    Remark

    The case and name of the field specified in the offColorPath property must match the case and name from the data model bound to the ADBoundViewController. Optionally, the value can be a forumla using a subset of the SQL syntax.

    Declaration

    Swift

    @IBInspectable public var offColorPath: String = ""
  • The name of the field from the date model or forumla (using SQL syntax) used to set the thumb tint color from.

    Example:

    // Given the following class
    class Category: ADDataTable {
    
        enum CategoryType: String, Codable {
            case local
            case web
        }
    
        static var tableName = "Categories"
        static var primaryKey = "id"
        static var primaryKeyType: ADDataTableKeyType = .computedInt
    
        var id = 0
        var added = Date()
        var name = ""
        var description = ""
        var enabled = true
        var quantity = 0
        var highlightColor = UIColor.white.toHex()
        var type: CategoryType = .local
        var icon: Data = UIImage().toData()
    
        required init() {
    
        }
    }
    
    // Set the text color based on a formula.
    mySwitch.thumbColorPath = "highlightColor"
    

    Remark

    The case and name of the field specified in the thumbColorPath property must match the case and name from the data model bound to the ADBoundViewController. Optionally, the value can be a forumla using a subset of the SQL syntax.

    Declaration

    Swift

    @IBInspectable public var thumbColorPath: String = ""
  • If true this switch cause the parent ADBoundViewController to update the form as the value changes.

    Declaration

    Swift

    @IBInspectable public var liveUpdate: Bool = false
  • Provides a link to the ADBoundViewController that the control is bound to.

    Declaration

    Swift

    public weak var controller: ADBoundViewController?
  • Provides a unique ID that is assigned to the control when it is bound to a ADBoundViewController.

    Remark

    You should never set or change this number yourself, this value will be managed by the ADBoundViewController and is used to handle form and keyboard events.

    Declaration

    Swift

    public var formID: Int = -1
  • Returns true if the value of the control can be edited by the user, else returns false.

    Declaration

    Swift

    public var isMutable: Bool
  • Sets the value of the switch from the given value. If the value is an Int or Float it will be converted to a Bool (1 = true and 0 = false. If the value is a String it will be converted to a Bool where the string values of true, yes or 1 = true and the values of "false", "no" or "0" =false`.

    Declaration

    Swift

    public func setValue(_ value: Any)

    Parameters

    value

    The value to set the switch to.

  • Sets the enabled state of the control from the given value. If the value is an Int or Float, 0 and 1 will be converted to false and true. If the value is a String, yes, on, true, 1 will be converted to true, all other values will result in false.

    Declaration

    Swift

    public func setEnabledState(_ value: Any)

    Parameters

    value

    The value to set the enabled state from.

  • Sets the hidden state of the control from the given value. If the value is an Int or Float, 0 and 1 will be converted to false and true. If the value is a String, yes, on, true, 1 will be converted to true, all other values will result in false.

    Declaration

    Swift

    public func setHiddenState(_ value: Any)

    Parameters

    value

    The value to set the enabled state from.

  • Sets the on color from the given value. If the value is a string, this routine will assume it holds a hex color specification in the form #RRGGBBAA.

    Declaration

    Swift

    public func setOnColor(_ value: Any)

    Parameters

    value

    The value to set the minimum track color from.

  • Sets the off color from the given value. If the value is a string, this routine will assume it holds a hex color specification in the form #RRGGBBAA.

    Declaration

    Swift

    public func setOffColor(_ value: Any)

    Parameters

    value

    The value to set the text color from.

  • Sets the thumb color from the given value. If the value is a string, this routine will assume it holds a hex color specification in the form #RRGGBBAA.

    Declaration

    Swift

    public func setThumbColor(_ value: Any)

    Parameters

    value

    The value to set the text color from.

  • Sets any control specific bound states (such as colors) with the values from the given ADRecord.

    Declaration

    Swift

    public func setControlSpecificStates(against data: ADRecord)

    Parameters

    data

    The raw data to bind the additional states to.

  • Returns the value of the switch.

    Declaration

    Swift

    public func getValue() -> Any

    Return Value

    The value of the switch as a Bool.