ITCB_SDK_Protocol

public protocol ITCB_SDK_Protocol

This is the main “generic” protocol, applicable to both Central and Peripheral.

The SDK defines an interface between Bluetooth LE devices and abstracts Apple’s Core Bluetooth Library.

The SDK can be instantiated as either a Bluetooth LE “Central,” or as a “Peripheral.”.

The role of the SDK is determined by which variant of the SDK is instantiated.

This is a teaching aid, and, as such, has an extremely limited and tightly-defined functionality. It is a Bluetooth expression of a “Magic 8-Ball” app.

Centrals are instantiated as ITCB_SDK_Central instances, and Peripherals are instantiated as ITCB_SDK_Peripheral instances. They are described as protocols, instead of concrete classes or structs, in order to assure opacity and flexibility.

All protocol members are required (Except for the internal createInstance() method; which is, in reality, required).

  • createInstance() Default implementation

    Factory function for instantiating Centrals or Peripherals.

    This is really for internal use only.

    Default Implementation

    This is just here to allow the protocol to make the func optional. It returns nil.

    Declaration

    Swift

    static func createInstance() -> ITCB_SDK_Protocol?

    Return Value

    A new instance of an SDK.

  • Any error condition associated with this instance. It may be nil.

    Declaration

    Swift

    var error: ITCB_Errors? { get }
  • This is true, if Core Bluetooth reports that the device Bluetooth interface is powered on and available for use.

    Declaration

    Swift

    var isCoreBluetoothPoweredOn: Bool { get }
  • This is a String that can be applied by the user. It will be advertised, or set to local CoreBluetooth Peripherals and Centrals.

    Declaration

    Swift

    var localName: String { get set }
  • This is an Array of observer objects associated with this SDK instance.

    Declaration

    Swift

    var observers: [ITCB_Observer_Protocol] { get set }
  • This adds the given observer to the list of observers for this SDK object. If the observer is already registered, nothing happens.

    Declaration

    Swift

    func addObserver(_ observer: ITCB_Observer_Protocol) -> UUID!

    Parameters

    observer

    The Observer Instance to add.

    Return Value

    The newly-assigned UUID. Nil, if the observer was not added.

  • This removes the given observer from the list of observers for this SDK object. If the observer is not registered, nothing happens.

    Declaration

    Swift

    func removeObserver(_ observer: ITCB_Observer_Protocol)

    Parameters

    observer

    The Observer Instance to remove.

  • This checks the given observer, to see if it is currently observing this SDK instance.

    Declaration

    Swift

    func isObserving(_ observer: ITCB_Observer_Protocol) -> Bool

    Parameters

    observer

    The Observer Instance to check.

    Return Value

    True, if the observer is currently in the list of SDK observers.