Skip to content

Instantly share code, notes, and snippets.

View joseph-elmallah's full-sized avatar

Joseph EL MALLAH joseph-elmallah

View GitHub Profile
@joseph-elmallah
joseph-elmallah / UIResponder+BasicErrorPropagation.swift
Last active September 1, 2018 22:53
Basic UIResponder for iOS error propagation
import UIKit
// The status of an error handler
enum ErrorHandlingStatus {
/// The error was handled successfully and the propagation should stop
case handled
/// The error was not handled and the should be propagated further more
case unhandled
}
@joseph-elmallah
joseph-elmallah / URL+UIResponder.swift
Created December 9, 2018 20:39
A decoupled way to propagate URL opening in an iOS app over the Responder chain
/// Conforming to this protocol allows for URL handling
protocol URLHandler {
/// Handle a URL
///
/// - Parameter url: The propagated url
/// - Returns: The handled status
func handleURL(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any], completionHandler completion: ((Bool) -> Void)?)
}
// MARK: - Error Propagation
@joseph-elmallah
joseph-elmallah / UIApplication+URLHandler.swift
Created December 9, 2018 20:47
The conformance of UIApplication to the URLHandler protocol
// MARK: - URLHandler conformance
extension UIApplication: URLHandler {
func handleURL(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any], completionHandler completion: ((Bool) -> Void)?) {
// If we reach the end of the responder chain without anyone handeling the URL, ask the Applciation to handle it
open(url, options: options, completionHandler: completion)
}
}
@joseph-elmallah
joseph-elmallah / GameOfLifeJ2ObjC.swift
Last active April 12, 2019 23:05
Game of life using J2ObjC
import UIKit
// This is a snippet for the Medium article:
// UIViewController that shows a board of 10x10 cells of Game of Life implementation.
class ViewController: UIViewController, GofCoreDisplayDriver {
/// The board is square. This defines the edge size of the board (10 x 10)
private let boardSize: Int = 10