Skip to content

Instantly share code, notes, and snippets.

@eriadam
Created February 2, 2018 15:28
Show Gist options
  • Save eriadam/1744b94f0ac5186dcfed2fda4412ff1d to your computer and use it in GitHub Desktop.
Save eriadam/1744b94f0ac5186dcfed2fda4412ff1d to your computer and use it in GitHub Desktop.
GKRuleSystem-example.swift
// 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