Skip to content

Instantly share code, notes, and snippets.

@farhadmpr
Created September 29, 2021 08:14
Show Gist options
  • Save farhadmpr/7e18c585bd9f644a6ce0a78cd7c6c5cb to your computer and use it in GitHub Desktop.
Save farhadmpr/7e18c585bd9f644a6ce0a78cd7c6c5cb to your computer and use it in GitHub Desktop.
Ambient Context #1
class LocationManager {
//....
static func isAuthorized() -> Bool {
switch authorizationStatus() {
case .authorizedAlways,
.authorizedWhenInUse:
return true
default:
return false
}
}
//....
}
class MapViewModel {
//....
func performCriticalBusinessLogic() {
if LocationManager.isAuthorized() {
// GPS Service Authroized
} else {
// GPS Service not authorized
}
}
func performAnotherCriticalBusinessLogic() {
let currentDate = Date()
if currentDate.isOnWeekend() {
// Perform business logic for weekends
} else {
// Perform business logic for week days
}
}
//....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment