Last active
December 24, 2020 08:28
-
-
Save fitsyu/b6726c98068507af95080e48ff49f434 to your computer and use it in GitHub Desktop.
Implementasi Protokol Kesehatan Menggunakan Swift
This file contains 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
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