Skip to content

Instantly share code, notes, and snippets.

@fikeminkel
Created April 15, 2018 13:08
Show Gist options
  • Save fikeminkel/8f94b1bd9318cf863d8c9fc1e0627447 to your computer and use it in GitHub Desktop.
Save fikeminkel/8f94b1bd9318cf863d8c9fc1e0627447 to your computer and use it in GitHub Desktop.
this one with an enum to force type safety. really messy though.
import UIKit
enum ServiceId {
case service(id: String)
func id() -> String {
switch self {
case .service(let id): return id
}
}
}
class Service {
let id: ServiceId
init(id: String) {
self.id = ServiceId.service(id: id)
}
}
class ServiceAvailability {
func checkAvailabilityOf(serviceId: ServiceId, handler: (ServiceId, Bool) -> ()) {
handler(serviceId, true)
}
}
let service = Service(id: "myServiceId")
let availability = ServiceAvailability()
availability.checkAvailabilityOf(serviceId: service.id) { id, available in
print("service \(id.id()) is available? \(available)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment