ReferenceValet
public final class ReferenceValet
A ReferenceValet help pass references to closures without creating retaining cycles or having to use captures list directly.
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference>(reference: Reference, in closure: @escaping (Reference) -> Void) -> () -> Void where Reference: AnyObjectParameters
referencereference to pass without retaining
closureclosure containing the business logic
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A>(reference: Reference, in closure: @escaping (Reference, A) -> Void) -> (A) -> Void where Reference: AnyObjectParameters
referencereference to pass without retaining
closureclosure containing the business logic
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A, B>(reference: Reference, in closure: @escaping (Reference, A, B) -> Void) -> (A, B) -> Void where Reference: AnyObjectParameters
referencereference to pass without retaining
closureclosure containing the business logic
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A, B, C>(reference: Reference, in closure: @escaping (Reference, A, B, C) -> Void) -> (A, B, C) -> Void where Reference: AnyObjectParameters
referencereference to pass without retaining
closureclosure containing the business logic
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, Result>(reference: Reference, in closure: @escaping (Reference) -> Result) -> () -> Result where Reference: AnyObject, Result: ExpressibleByNilLiteralParameters
referencereference to pass without retaining
closureclosure containing the business logic
Return Value
the wrapped closure’s result or nil if reference doesn’t exits
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A, Result>(reference: Reference, in closure: @escaping (Reference, A) -> Result) -> (A) -> Result where Reference: AnyObject, Result: ExpressibleByNilLiteralParameters
referencereference to pass without retaining
closureclosure containing the business logic
Return Value
the wrapped closure’s result or nil if reference doesn’t exits
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A, B, Result>(reference: Reference, in closure: @escaping (Reference, A, B) -> Result) -> (A, B) -> Result where Reference: AnyObject, Result: ExpressibleByNilLiteralParameters
referencereference to pass without retaining
closureclosure containing the business logic
Return Value
the wrapped closure’s result or nil if reference doesn’t exits
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A, B, C, Result>(reference: Reference, in closure: @escaping (Reference, A, B, C) -> Result) -> (A, B, C) -> Result where Reference: AnyObject, Result: ExpressibleByNilLiteralParameters
referencereference to pass without retaining
closureclosure containing the business logic
Return Value
the wrapped closure’s result or nil if reference doesn’t exits
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, Result>(reference: Reference, defaultingTo result: Result, in closure: @escaping (Reference) -> Result) -> () -> Result where Reference: AnyObjectParameters
referencereference to pass without retaining
closureclosure containing the business logic
Return Value
the wrapped closure
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A, Result>(reference: Reference, defaultingTo result: Result, in closure: @escaping (Reference, A) -> Result) -> (A) -> Result where Reference: AnyObjectParameters
referencereference to pass without retaining
closureclosure containing the business logic
Return Value
the wrapped closure
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A, B, Result>(reference: Reference, defaultingTo result: Result, in closure: @escaping (Reference, A, B) -> Result) -> (A, B) -> Result where Reference: AnyObjectParameters
referencereference to pass without retaining
closureclosure containing the business logic
Return Value
the wrapped closure
-
Passes the given reference as an argument instead of having to create a capture list and check boilerplate code
Declaration
Swift
public static func enclose<Reference, A, B, C, Result>(reference: Reference, defaultingTo result: Result, in closure: @escaping (Reference, A, B, C) -> Result) -> (A, B, C) -> Result where Reference: AnyObjectParameters
referencereference to pass without retaining
closureclosure containing the business logic
Return Value
the wrapped closure
-
Calls the given closure with the reference passed to it (instead of having to add capture list and then check if reference exists).
Declaration
Swift
public static func call<Reference>(_ target: (@escaping () -> Void) throws -> Void, with reference: Reference, on closure: @escaping (Reference) -> Void) rethrows where Reference: AnyObjectParameters
targetthe function to pass the trailing closure to
referencereference to pass without retaining
closureclosure containing the final argument to be passed to the target function
-
Calls the given closure with the reference passed to it (instead of having to add capture list and then check if reference exists).
Declaration
Swift
public static func call<Reference, X, Y>(_ target: (@escaping () -> X) throws -> Y, with reference: Reference, on closure: @escaping (Reference) -> X) rethrows -> Y where Reference: AnyObject, X: ExpressibleByNilLiteralParameters
targetthe function to pass the trailing closure to
referencereference to pass without retaining
closureclosure containing the final argument to be passed to the target function
Return Value
the result of the target function
-
Calls the given closure with the reference passed to it (instead of having to add capture list and then check if reference exists).
Declaration
Swift
public static func call<Reference, X, Y>(_ target: (@escaping () -> X) throws -> Y, with reference: Reference, defaultingTo result: X, on closure: @escaping (Reference) -> X) rethrows -> Y where Reference: AnyObjectParameters
targetthe function to pass the trailing closure to
referencereference to pass without retaining
resultthe default result in case the reference no long exists
closureclosure containing the final argument to be passed to the target function
Return Value
the result of the target function
-
Calls async on the given dispatch queue (or the main queue if not specified) with the closure that is supplied with the give reference. Saves adding the capture list and checking if reference exists.
Declaration
Swift
public static func async<Reference>(_ reference: Reference, on queue: DispatchQueue = DispatchQueue.main, in closure: @escaping (Reference) -> Void) where Reference: AnyObjectParameters
referencereference to pass without retaining
queuequeue to run task on
closureclosure containing the task
ReferenceValet Class Reference