This file contains 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 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 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 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 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 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 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() |
This file contains 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
// | |
// Downloader.swift | |
// Copyright (c) 2015 Andrew James. All rights reserved. | |
// | |
import Foundation | |
import UIKit | |
public class Downloader : NSObject | |
{ |
This file contains 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
// | |
// DispatchUtility.swift | |
// | |
// Copyright (c) 2015 Andrew James. All rights reserved. | |
// | |
import Foundation | |
func GCDDispatchMain(closure:()->()) | |
{ |
This file contains 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 | |
func find4Largest(numbers:[Int]) -> [Int] | |
{ | |
let count = 4 | |
assert(count < numbers.count, "Error: numbers must have at least \(count) elements") | |
if numbers.count < 2 | |
{ | |
return numbers | |
} |