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
import Foundation | |
class Bakery { | |
func bakeCake() -> Cake? { | |
let ingredientStorage = IngredientStorage() | |
if let chocolateFlavor = ingredientStorage.consume(flavor: .chocolate) { | |
return Cake(flavor: chocolateFlavor) | |
} else if let vanillaFlavor = ingredientStorage.consume(flavor: .vanilla) { | |
return Cake(flavor: vanillaFlavor) | |
} |
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
import Foundation | |
/* | |
This is used by NSNotification.Name to allow enum-like members, | |
but where new members can be added in an extension! | |
enum Directions: String { | |
case north = "North" | |
} | |
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
#import <Foundation/Foundation.h> | |
#define dep(p) [[Registry shared] resolve: (@protocol(p))] | |
#define reg(c, p) [[Registry shared] register:[c class] forProtocol:@protocol(p)] | |
@interface Registry : NSObject | |
@property (nonatomic, strong) NSMutableDictionary * _Nonnull classRegister; | |
@property (nonatomic, strong) NSMutableDictionary * _Nonnull classInstances; | |
+(instancetype _Nonnull)shared; | |
- (id _Nullable)resolve:(Protocol * _Null_unspecified)aProtocol; |
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
// | |
// ImageViewerViewController.swift | |
// PhotoViewer | |
// | |
// Created by Andrew James on 2/26/16. | |
// Copyright © 2016 aj. All rights reserved. | |
// | |
import UIKit |
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 String | |
{ | |
func attributeString(font1:UIFont, font2:UIFont, color1:UIColor = UIColor.blackColor(), color2:UIColor = UIColor.blackColor()) -> NSAttributedString | |
{ | |
let attributes1 = [NSFontAttributeName:font1, NSForegroundColorAttributeName:color1] | |
let attributes2 = [NSFontAttributeName:font2, NSForegroundColorAttributeName:color2] | |
return attributeString("|", attributes1:attributes1, attributes2:attributes2) | |
} | |
func attributeString(delimiter:Character, attributes1:[String:AnyObject], attributes2:[String:AnyObject]) -> NSAttributedString |
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 NSMutableAttributedString | |
{ | |
func replace(target:String, with replacement:String, attributes:[String:NSObject]?) | |
{ | |
var text = self.string | |
var error:NSError? | |
var regex = NSRegularExpression(pattern:target, options:.IgnoreMetacharacters, error:nil) | |
var range = NSMakeRange(0, count(text)) | |
regex?.enumerateMatchesInString(text, options:nil, range: range, usingBlock: { | |
(result:NSTextCheckingResult!, flags:NSMatchingFlags, stop:UnsafeMutablePointer<ObjCBool>) -> Void in |
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 NSAttributedString | |
{ | |
convenience init?(html: String) { | |
if let data = html.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) | |
{ | |
let options = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType] | |
self.init(data: data, options: options, documentAttributes: nil, error: nil) | |
} | |
else | |
{ |
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
class mySingletonClass | |
{ | |
class var default: mySingletonClass | |
{ | |
struct Static | |
{ | |
static var instance: mySingletonClass? | |
static var token: dispatch_once_t = 0 | |
} | |
dispatch_once(&Static.token) { |
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
import Foundation | |
public extension String | |
{ | |
public func contains(substring:String) -> Bool | |
{ | |
return self.rangeOfString(substring, options: NSStringCompareOptions.LiteralSearch, range: nil, locale: nil) != nil | |
} | |
} |
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
import UIKit | |
import XCTest | |
let kAsyncTimeout = NSTimeInterval(30) | |
class AsyncTestCase: XCTestCase | |
{ | |
var expectation: XCTestExpectation! | |
override func setUp() |