UniqueRunner
public class UniqueRunner
A class used to run a function only once.
Example:
let ur = UniqueRunner()
var result = ur.runOnce(addNumbers(2, 2))
result = ur.runOnce(addNumbers(5, 5))
result = ur.runOnce(addNumbers(10, 10))
result == 4 // true
-
Indicates if the method has run already
Declaration
Swift
public var hasRun = false
-
Run any method once and always returns the result of the run when called multiple times
Parameter
Parameter function: the function that needs to run only once
Returns
the function result
Declaration
Swift
public func runOnce<T>(_ function: @autoclosure () -> T) -> T
Parameters
function
the function that needs to run only once
Return Value
the function result