Skip to content

Instantly share code, notes, and snippets.

View VinceBurn's full-sized avatar

Vincent Bernier VinceBurn

  • OctoByte Logiciel Inc
  • Montréal, QC
View GitHub Profile
@VinceBurn
VinceBurn / JSONFactory.swift
Created September 14, 2018 15:48
JSONFactory Protocol Extension
protocol JSONFactory {
static func make(jsonData: Data?) -> Self?
}
extension JSONFactory where Self: Decodable {
static func make(jsonData: Data?) -> Self? {
guard let jsonData = jsonData,
let result = try? JSONDecoder().decode(Self.self, from: jsonData) else {
return nil
}
@VinceBurn
VinceBurn / gist:c63bbdecdb5626af2a9c4a3dfa33cc6d
Last active March 7, 2018 13:39
Generic equality of potentially null values
/**
* Compare 2 nullable for equality. If both are null they are considered to be equal.
*
* @param lhs Left Hand Side value
* @param rhs Right Hand Side value
* @param <T> A Type on which `equals()` will be called
* @return true if the 2 values are equals taking `null` into account.
*/
public static <T> Boolean isEqual(@Nullable T lhs, @Nullable T rhs) {
Boolean result;