Other Classes
The following classes are available globally.
-
Base class for synchronous commands that preserves typed throws.
Subclass this and override
execute(payload:) throws(CommandError)for commands that complete their work synchronously (e.g. setting a user property, logging an event).The protocol requirement is handled by a
See morefinalwrapper — subclasses cannot accidentally override the wrong overload.Declaration
Swift
open class SyncCommand : Command -
Listens for application lifecycle events and emits status changes.
See moreDeclaration
Swift
public class ApplicationStatusListener : NSObject -
A class that wraps a completion block and makes sure it can only be completed once.
To be sure that the completion block is not called by someone else, you should name the variable holding the instance of this class with the same name of the completion block that was passed as a parameters.
Example where completion block has the same parameter of the inner function:
func doSomeAsyncOperation(request: URLRequest, completion: @escaping (Result<Any, Error>) -> Void) { let completion = SelfDestructingResultCompletion(completion: completion) _ = NetworkingClient.shared.send(request, completion: completion.complete) }Example where completion block has different parameters of the inner function:
func doSomeAsyncOperation(request: URLRequest, completion: @escaping (Result<Any, Error>) -> Void) { let completion = SelfDestructingResultCompletion(completion: completion) URLSession.shared.dataTask(request) { data, request, error in if let error = error { completion.fail(error) } else { completion.success(data) } }.resume() }Main usecase is for completing immediately something that is cancelled, without the need to add more logic to avoid duplicate call of the completion.
See moreDeclaration
Swift
public class SelfDestructingResultCompletion<Success, Failure> : SelfDestructingCompletion<Result<Success, Failure>> where Failure : Error -
A class that wraps a completion block and makes sure it can only be completed once.
To be sure that the completion block is not called by someone else, you should name the variable holding the instance of this class with the same name of the completion block that was passed as a parameters.
Main usecase is for completing immediately something that is cancelled, without the need to add more logic to avoid duplicate call of the completion.
See moreDeclaration
Swift
public class SelfDestructingCompletion<Param> -
A utility class that wraps a
DispatchGroupand makes safer to use and includes an array of results in the completion.Differently from the
See moreDispatchGroup, if the first work completes synchronously the completion won’t be called until all the other work is completed too. All the results then are collected and returned in the completion.Declaration
Swift
public class TealiumDispatchGroup -
A wrapper class around DispatchQueue to only dispatch asynchronously when we are on a different queue.
Making it dispatch synchronously in a generic library would instead be not safe and could lead to deadlocks. An example of deadlock that would look safe is this:
DispatchQueue.main.async { let queue = TealiumQueue(label: "something") queue.ensureOnQueue { print("This will print") DispatchQueue.main.sync { // This is something that a user might do on one of our completions print("This will never print") } } queue.syncOnQueue { // This is something that might be part of our library if we do introduce a method like this print("This will never print") } }Therefore we only have, and only should have, an async method which is
See moreensureOnQueue.Declaration
Swift
public class TealiumQueue -
Utility to replace double brace wrapped text with values extracted from a
See moreDataObject.Declaration
Swift
public class TemplateProcessor
View on GitHub
Other Classes Reference