By Xmartlabs SRL.
Ecno was inspired by Once Android library. It's a task state manager built on top of UserDefaults in pure Swift 4. This abstraction allows you to mark 'tasks' as done, 'to-do' and check for those states.
Ecno is ideal for:
First you need to initialize it:
Ecno.initialize()
Note: you should initialize it when your app gets launched.
Then, you can check whether a task was done by:
if !Ecno.beenDone("task") {
//...
Ecno.markDone("task")
}
Also, you can check for specific requirements about a certain task:
if Ecno.beenDone("task", scope: .appSession, numberOfTimes: .moreThan(3)) {
// do stuff
}
or
if Ecno.beenDone("task", scope: .since(20.minutes), numberOfTimes: .lessThan(3)) {
// do stuff
}
Additionally, you can program a 'to do' task by:
Ecno.toDo("show banner", scope: .until(3.hours), info: ["name": "bannerName"])
and then query if you need to do that task:
if Ecno.needToDo("show banner") {
let info = Ecno.infoForToDo("show banner") // ["name": "bannerName"]
// ...
}
Any type conforming to the Task
protocol. Since it would be the most common case, the String
type already conforms to Task
.
public protocol Task {
var tag: String { get }
}
Scopes represents periods of time within the application.
.appInstall
.appVersion
.appSession
.since(TimeInterval)
TimeInterval
time ago from now. For instance, .since(2.days)
.until(TimeInterval)
TimeInterval
from now. For instance, .until(3.hours)
. This should be useful to set a 'to do' task that expires.func toDo(_ task: Task, scope: Scope? = nil, info: [AnyHashable: Any]? = nil)
func needToDo(_ task: Task) -> Bool
func infoForToDo(_ task: Task) -> [AnyHashable: Any]?
toDo(...)
function)func lastDone(_ task: Task) -> Date?
func beenDone(_ task: Task, scope: Scope = .appInstall, numberOfTimes: CountChecker = .moreThan(0)) -> Bool
func markDone(_ task: Task)
Before contribute check the CONTRIBUTING file for more info.
If you use Ecno in your app We would love to hear about it! Drop us a line on twitter.
Follow these 3 steps to run Example project:
CocoaPods is a dependency manager for Cocoa projects.
To install Ecno, simply add the following line to your Podfile:
pod 'Ecno', '~> 3.0'
Carthage is a simple, decentralized dependency manager for Cocoa.
To install Ecno, simply add the following line to your Cartfile:
github "xmartlabs/Ecno" ~> 3.0
This can be found in the CHANGELOG.md file.
link |
Stars: 102 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics