Created
April 15, 2018 13:08
-
-
Save fikeminkel/8f94b1bd9318cf863d8c9fc1e0627447 to your computer and use it in GitHub Desktop.
this one with an enum to force type safety. really messy though.
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
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