increase minimum OS version and remove spin lock.
Swift allows for lazy variables out-of-the-box, however they’re fairly restricted.
let lazyInt = Lazy(1) print(lazyInt.wasMade) // false print(lazyInt.value) // 1 print(lazyInt.wasMade) // true
Support arithmetic operations:
let lazyInt = Lazy<Int>{ 1 + 2 * 5 } * 4 + 10 print(lazyInt.wasMade) // false print(lazyInt.value) // 54 print(lazyInt.wasMade) // true
Short syntax:
let lazyInt = Lazy(1) print(*lazyInt) // 1
let providerInt = Provider(1) print(lazyInt.value) // 1
let providerInt = Provider<Int>{ 1 + 2 * 5 } * 4 + 10 print(providerInt.value) // 54
let providerInt = Provider(1) print(*providerInt) // 1
var counter: Int = 0 let lazyInt = Lazy<Int> { counter += 1 return counter } print(lazyInt.value) // 1 print(lazyInt.value) // 1 print(lazyInt.value) // 1 lazyInt.clear() // no provider print(lazyInt.value) // 2 print(lazyInt.value) // 2 print(lazyInt.value) // 2
var counter: Int = 0 let providerInt = Provider<Int> { counter += 1 return counter } print(providerInt.value) // 1 print(providerInt.value) // 2 print(providerInt.value) // 3
Add Provider with arguments:
let provider = Provider2<String, Int, Double> { "\($0) + \($1) = \($0 + $1)" } print(provider.value(10, 20.0)) // "10 + 20.0 = 30.0"
Support 1, 2, 3, 4, 5 arguments count.
To install SwiftLazy with CocoaPods, add the following lines to your Podfile: pod 'SwiftLazy'
pod 'SwiftLazy'
github “ivlevAstef/SwiftLazy”
iOS 11.0+,macOS 10.13+,tvOS 11.0+, watchOS 4.0+, Linux; ARC
Please raise a GitHub issue.
You can feel free to ask the question at e-mail: ivlev.stef@gmail.com.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
SwiftLazy
Swift allows for lazy variables out-of-the-box, however they’re fairly restricted.
Features
Usage
Lazy
Support arithmetic operations:
Short syntax:
Provider
Support arithmetic operations:
Short syntax:
Difference Lazy vs Provider
Version 1.1.0
Add Provider with arguments:
Support 1, 2, 3, 4, 5 arguments count.
Install
Via CocoaPods.
To install SwiftLazy with CocoaPods, add the following lines to your Podfile:
pod 'SwiftLazy'
Via Carthage.
github “ivlevAstef/SwiftLazy”
The library is integrated with DITranquillity
Requirements
iOS 11.0+,macOS 10.13+,tvOS 11.0+, watchOS 4.0+, Linux; ARC
Feedback
I’ve found a bug, or have a feature request
Please raise a GitHub issue.
Question?
You can feel free to ask the question at e-mail: ivlev.stef@gmail.com.