Created
February 2, 2018 15:28
-
-
Save eriadam/1744b94f0ac5186dcfed2fda4412ff1d to your computer and use it in GitHub Desktop.
GKRuleSystem-example.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Being online asserts the online navigation option. | |
// And retracts the offline option. | |
self.add(GKRule(blockPredicate: { ruleSystem -> Bool in | |
return Reachability.isOnline == true | |
}, action: { ruleSystem in | |
log.verbose("Rule 1: User is online") | |
ruleSystem.assertFact("navigableRoute") | |
ruleSystem.retractFact("offlineNavigableRoute") | |
})) | |
// In the view controller | |
let isOnlineNavigable: Bool = self | |
.ruleSystem? | |
.grade(forFact: "navigableRoute") == 1 | |
// There is also AND and OR relations for different facts | |
let grade = self.maximumGrade(forFacts: [ | |
"someFact", | |
"anotherFact", | |
"yetAnotherFactoid" | |
]) | |
let grade = self.minimumGrade(forFacts: [ | |
"someFact", | |
"anotherFact" | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment