This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Very slightly adapted from http://stackoverflow.com/a/30141700/106244 | |
// 99.99% Credit to Martin R! | |
// Mapping from XML/HTML character entity reference to character | |
// From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references | |
private let characterEntities : [String: Character] = [ | |
// XML predefined entities: | |
""" : "\"", | |
"&" : "&", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Recursively validates all python files with pyflakes that were modified | |
# since the last validation, and provides basic stats. Ignores hidden | |
# directories. | |
# | |
# NOTE: | |
# You should set your favourite version control system to ignore | |
# the validate.db file that is used to track when which files | |
# have changed since last validation. | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDate+InternetDateTime.h | |
// MWFeedParser | |
// | |
// Created by Michael Waterfall on 07/10/2010. | |
// Copyright 2010 Michael Waterfall. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* System Versioning Preprocessor Macros | |
*/ | |
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) | |
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) | |
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) | |
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) | |
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol Changeable {} | |
extension Changeable { | |
/// Calls the `changes` closure passing the receiver value as an `inout` parameter. The final value of the argument | |
/// after the `changes` closure returns is then returned from this method. Benefits to using this function come | |
/// when used against value types. | |
/// | |
/// Example: | |
/// | |
/// extension UIEdgeInsets: Changeable {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Material: String { | |
case wood, metal, glass, other | |
} | |
extension Material: Codable {} | |
extension Material: UnknownCaseRepresentable { | |
static let unknownCase: Material = .other | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol UnknownCaseRepresentable: RawRepresentable, CaseIterable { | |
static var unknownCase: Self { get } | |
} | |
extension UnknownCaseRepresentable where Self.RawValue: Equatable { | |
init(rawValue: RawValue) { | |
let value = Self.allCases.first(where: { $0.rawValue == rawValue }) | |
self = value ?? Self.unknownCase | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Material { | |
init(from decoder: Decoder) throws { | |
self = try Material(from: decoder, default: .other) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension RawRepresentable where RawValue: Decodable { | |
init(from decoder: Decoder, default: Self) throws { | |
let container = try decoder.singleValueContainer() | |
let rawValue = try container.decode(RawValue.self) | |
self = Self(rawValue: rawValue) ?? `default` | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Material { | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
let rawMaterial = try container.decode(String.self) | |
self = Material(rawValue: rawMaterial) ?? .other | |
} | |
} |
NewerOlder