Skip to content

Instantly share code, notes, and snippets.

View avdwerff's full-sized avatar

Alexander van der Werff avdwerff

View GitHub Profile
extension Array where Element: Comparable {
func mergeSort() -> [Element] {
if count <= 1 { return self }
else {
let left = Array(self[0 ..< count/2])
let right = Array(self[count/2 ..< count])
return merge(left.mergeSort(), right: right.mergeSort())
}
}
protocol JSONInitable {
init(data: JSON)
}
extension JSON {
func to<T where T: JSONInitable>(type: T.Type) -> [T] {
return self.arrayValue.map {
return T(data: $0)
}
}
import UIKit
class ActivityIndicatorView: UIView {
private lazy var gradientLayer: CAGradientLayer = {
let gradient = CAGradientLayer()
gradient.locations = [0.5, 1]
gradient.startPoint = CGPointMake(0.0, 0.0)
gradient.endPoint = CGPointMake(1.0, 0.8)
import Foundation
//https://en.wikipedia.org/wiki/XML
class ValidXMLProperties {
static let shared = ValidXMLProperties()
static let excludedElementNameCharactersPattern = "!|\"|#|\\$|%|&|\\'|\\(|\\)|\\*|\\+|,|/|;|\\<|=|\\>|\\?|\\@|\\[|\\\\|\\]|\\^|`|\\{|\\||\\}|~"
static let excludedElementNameStartCharactersPattern = "-|\\.|[\\d]"