Skip to content

Instantly share code, notes, and snippets.

View TYRONEMICHAEL's full-sized avatar
🥸

Tyrone Avnit TYRONEMICHAEL

🥸
View GitHub Profile
@TYRONEMICHAEL
TYRONEMICHAEL / DisplayGame.swift
Created March 30, 2021 04:04
Game Mode Refactor
enum Mode {
case small
case medium
struct Dimensions {
let colorDepth: Int
let width: Int
let height: Int
}
@TYRONEMICHAEL
TYRONEMICHAEL / 08.swift
Created May 11, 2018 14:10
Extending your modules using a plugin architecture
let authenticator = Authenticator()
authenticator.authenticateSuccessfully()
//authenticator.authenticateUnsuccessfully()
@TYRONEMICHAEL
TYRONEMICHAEL / 07.swift
Created May 11, 2018 14:08
Extending your modules using a plugin architecture
LoginContainer.instance.register(plugin: PostLoginSuccessPlugin.self, with: UserProfilePostLoginPluginImplementation())
LoginContainer.instance.register(plugin: PostLoginSuccessPlugin.self, with: UserFeedPostLoginPluginImplementation())
LoginContainer.instance.register(plugin: PostLoginSuccessPlugin.self, with: LocalStoragePostLoginPluginImplementation())
LoginContainer.instance.register(plugin: PostLoginFailurePlugin.self, with: LocalStoragePostLoginPluginImplementation())
@TYRONEMICHAEL
TYRONEMICHAEL / 06.swift
Created May 11, 2018 14:05
Extending your modules using a plugin architecture
final class UserProfilePostLoginPluginImplementation: PostLoginSuccessPlugin {
func successfulLogin(userId: String) {
print("Fetching user profile with id \(userId)...")
}
}
final class UserFeedPostLoginPluginImplementation: PostLoginSuccessPlugin {
@TYRONEMICHAEL
TYRONEMICHAEL / 05.swift
Created May 11, 2018 14:01
Extending your modules using a plugin architecture
public final class Authenticator {
public init() {}
public func authenticateSuccessfully() {
print("Logging in...")
print("Logged in successfully...")
LoginContainer.instance.resolve(forPlugin: PostLoginSuccessPlugin.self).forEach(successfulLogin)
}
@TYRONEMICHAEL
TYRONEMICHAEL / 04.swift
Created May 11, 2018 13:52
Extending your modules using a plugin architecture
public final class LoginContainer {
private var registry = [String: [() -> Any]]()
private init() {}
}
public extension LoginContainer {
static let instance = LoginContainer()
@TYRONEMICHAEL
TYRONEMICHAEL / 03.swift
Created May 11, 2018 13:40
Extending your modules using a plugin architecture
public enum FailedLogin: Error {
case userNotFound
}
public protocol PostLoginFailurePlugin {
func failedLogin(error: FailedLogin)
@TYRONEMICHAEL
TYRONEMICHAEL / 02.swift
Created May 11, 2018 13:39
Extending your modules using a plugin architecture
public typealias UserId = String
public protocol PostLoginSuccessPlugin {
func successfulLogin(userId: UserId)
}
@TYRONEMICHAEL
TYRONEMICHAEL / 01.swift
Created May 11, 2018 13:35
Extending your modules using a plugin architecture
public final class Authenticator {
public init() {}
public func authenticateSuccessfully() {
print("Logging in...")
print("Logged in successfully...")
}
public func authenticateUnsuccessfully() {
@TYRONEMICHAEL
TYRONEMICHAEL / 09.swift
Created March 27, 2018 13:36
Cached Promises
func getCurrentUser() -> Promise<User> {
if let existing = cache.getCurrentUser() { return existing }
let user = Promise<User> { fulfill, reject in
DispatchQueue.global(qos: .background).async {
let user = self.dummyServiceCall()
DispatchQueue.main.asyncAfter(deadline: self.delay) {
fulfill(user)
}
}