Skip to content

Instantly share code, notes, and snippets.

@fitsyu
Last active December 24, 2020 08:28
Show Gist options
  • Save fitsyu/b6726c98068507af95080e48ff49f434 to your computer and use it in GitHub Desktop.
Save fitsyu/b6726c98068507af95080e48ff49f434 to your computer and use it in GitHub Desktop.
Implementasi Protokol Kesehatan Menggunakan Swift
protocol Kesehatan {
func memakaiMasker()
func menjagaJarak()
func mencuciTangan()
}
class MauSehat: /* implements */ Kesehatan {
func memakaiMasker() {
if let masker = wearables.select { \.type == .faceMask } {
self.wear(masker)
} else {
// TODO: Buy masker!
}
}
func menjagaJarak() {
let myDistanceObserver = LocationDifferenceObserver()
myDistanceObserver.handler = { nearbyDistances in
let closestNearbyToMe = nearbyDistances.sorted(<).first
if closestNearbyToMe < 1.m {
let requiredDistance = 1.m - closestNearbyToMe
self.take(requiredDistance)
}
}
myDistanceObserver.start()
}
func mencuciTangan() {
let handDampness = self.hands.both.read(state: .dampness).level
if handDampness > 100 {
// get the nearest water source and go there
let places = map.find(keywords: "water", "bathroom", "faucet")
guard let nearestPlace = places.sort { $0 > myDistance } else { useHandSanitizer() }
navigator.guide(to: nearestPlace)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment