Swift Module: Delegate

Swift Module: Delegate

by on ‎02-21-2017 08:45 AM - edited on ‎12-22-2017 08:51 AM by (455 Views)

Purpose

A multicast delegate handler to allow delegates to monitor or suppress dispatch events.

Supported Platforms

  • iOS
  • tvOS
  • watchOS
  • macOS

External Dependencies

Foundation

Recommended Usage

Usage of this module is optional. You only need to use it if you need fine control over individual dispatches/events (e.g. to block an event from being sent, or to monitor tracking calls for success/failure).

Included Variables

No additional variables are introduced by this module.

Public API

add

Adds a weak pointer to a class instance conforming to the TealiumDelegate protocol.

add(delegate: TealiumDelegate)

Parameters Type Description
delegate TealiumDelegate Any class conforming to the TealiumDelegate protocol.
// SAMPLE
func someSetupMethod {
    
    // Assuming 'tealium' was initialized earlier and "self" conforms to TealiumDelegate protocol
    tealium.delegates().add(delegate:self)
}

remove

Removes the weak pointer reference to the given class conforming to the TealiumDelegate protocol.

remove(delegate: TealiumDelegate)

Parameters Type Description
delegate TealiumDelegate Any class conforming to the TealiumDelegate protocol.
// SAMPLE
func someSetupMethod {
    
    // Assuming 'tealium' was initialized earlier and "self" conforms to TealiumDelegate protocol
    tealium.delegates().remove(delegate:self)
}

removeAll

Removes all weak pointers from tracking.

removeAll()

// SAMPLE
func someSetupMethod {
    
    // Assuming 'tealium' was initialized earlier    tealium.delegates().removeAll()
}

TealiumDelegate Protocol

tealiumShouldTrack()

If method returns true, the tracking call will be allowed to complete. If method returns false, tracking call will be canceled.

tealiumShouldTrack(data: [String:Any]) -> Bool

Parameters Description Example Value
data [String:Any] dictionary of data. ["somekey" : "somevalue"]
// SAMPLE
class SomeClass {
    
    func someSetupMethod {
        // Presuming 'tealium' initialized earlier
        tealium.delegates().add(delegate:self)
    }

}

extension SomeClass : TealiumDelegate {
    func tealiumShouldTrack(data:[String:Any]) -> Bool {
        // Can check keys and values for data that should trigger a false, otherwise..
        return true
    }
}

tealiumTrackCompleted()

Allows monitoring of completed track calls and handling of any errors

tealiumTrackCompleted(success: Bool, info: [String:Any]?, error: Error?)

Parameters Description Example Value
success Boolean if dispatch completed acceptably. true
info Dictionary of the original payload and any other returned data regarding dispatch. ["somekey" : "somevalue"]
error Error, if any, encountered during dispatch processing. Error from a module, e.g. TealiumCollectError.xErrorDetected
// SAMPLE
class SomeClass {
    
    func someSetupMethod {
        // Presuming 'tealium' initialized earlier
        tealium.delegates().add(delegate:self)
    }

}

extension SomeClass : TealiumDelegate {
    func tealiumTrackCompleted(success: Bool, info: [String:Any]?, error: Error?) {
        // Can check if successful, response info, and if any errors occurred.
    }
}

Future Improvements

No planned changes

Change Log

Build 1

  • Initial release