Functions
The following functions are available globally.
-
A publisher that immediately throws
– Use case Sometimes a function returns a publisher, but we need to unwap a value or perform a try catch before a publisher can be created. In this instance we can return this publisher instead to allow the publisher chain to handle those errors.
Declaration
Swift
public func ThrowingPublisher<T>(forType type: T.Type, throws error: Error) -> AnyPublisher<T, Error>
Parameters
type
The expected type of the publisher
error
The error to throw
Return Value
AnyPublisher
That fails immediately -
Unwrap or throw
Throws
The error from the rightvar x: Int? = nil let y = try x ??? SomeError() // Throws some Error var value: Int? = 1 let z = try value ??? SomeError() // unwraps value
Declaration
Swift
public func ??? <T>(left: Optional<T>, right: Error) throws -> T
Parameters
left
Any Optional
right
Error
Return Value
The unwrapped optional from the left
-
Runs the passed function on the main thread
Declaration
Swift
public func onMain(_ execute: @escaping () -> Void)
Parameters
execute
A function to execute on the main thread