Skip to content

Instantly share code, notes, and snippets.

View Constraint.swift
import Foundation
import UIKit
class ConstraintTransaction {
private var constraints: [Constraint] = []
func add(_ constraint: Constraint) {
constraints.append(constraint)
}
View ConstraintDSL.swift
import UIKit
class ConstraintDSL {
private let view: UIView
private var chain: [NSLayoutConstraint] = []
init(_ view: UIView) {
self.view = view
}
View providers.swift
// Define Provider Protocols
protocol NetworkProvider {
var networkingService: NetworkServiceProtocol
}
protocol LoggingProvider {
var loggerService: LoggerServiceProtocol
}
protocol ConfigurationProvider {
View clean-pbxproj.js
const Promise = require('bluebird');
const fs = require('fs');
const LineByLine = require('n-readlines');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
const filesWithoutExtension = [
'Podfile',
'Mintfile',
].reduce((acc, f) => { acc[f.toLowerCase()] = true; return acc; }, {}); // Convert to Set with lowercased filenames.
View JSONValue.c.swift
extension JSONValue {
public var value: JSONPrimitive? {
switch self {
case .object(let value): return value
case .array(let value): return value
case .string(let value): return value
case .number(let value): return value
case .boolean(let value): return value
case .null: return nil
View JSONValue.b.swift
extension JSONValue: Decodable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let value = try? container.decode(Bool.self) {
self = .boolean(value)
} else if let value = try? container.decode(Double.self) {
// Double covers Int as well
self = .number(value)
} else if let value = try? container.decode(String.self) {
View JSONValue.a.swift
public enum JSONValue {
case object([String: JSONValue])
case array([JSONValue])
case string(String)
case number(Double)
case boolean(Bool)
case null
}
View JSONValue.swift
public enum JSONValue {
case object([String: JSONValue])
case array([JSONValue])
case string(String)
case number(Double)
case boolean(Bool)
case null
public var value: JSONPrimitive? {
View JSONValueTests.swift
import XCTest
fileprivate extension JSONValue {
var objectValue: [String: JSONValue]? {
switch self {
case .object(let value): return value
default: return nil
}
}
var arrayValue: [JSONValue]? {
View JSONPrimitive.swift
/**
JSONPrimitive represents any Swift type which can be interchanged with a primitive
JSON type. Use this protocol instead of `Any` when dealing with JSON data.
*/
public protocol JSONPrimitive {}
/**
Int is excluded here because JSON only has one "type" for numbers,
so we always use Double to avoid lossy conversion.
*/