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 HasTitle { | |
var ht_title: String {get set} | |
} | |
extension UIBarButtonItem: HasTitle { | |
var ht_title: String { | |
get { | |
return self.title ?? "" | |
} | |
set { |
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 | |
struct MainScene { | |
let vc: UIViewController | |
let nc: UINavigationController | |
init(vc: UIViewController) { | |
self.vc = vc | |
self.nc = UINavigationController(rootViewController: vc) | |
} | |
} |
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
func z_map<S : SequenceType, T>(source: S, transform: (S.Generator.Element) -> T?) -> [T] { | |
// easy, right? =) | |
return reduce(source, []) { r, i in map( transform(i) ) { r + [$0] } ?? r } | |
} |
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 ProtocolA {} | |
protocol ProtocolB: ProtocolA {} | |
protocol ProtocolC { | |
func act() | |
} | |
protocol ProtocolD { | |
typealias V | |
func act() | |
} |
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
//In Swift 1.x this works and `properties` are casted to `[NSObject: AnyObject]`: | |
func imageOwnerWithURL(url: NSURL) -> ZMImageOwner! { | |
if let source = CGImageSourceCreateWithURL(url, nil), | |
properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [NSObject: AnyObject], | |
imageWidth = (properties[kCGImagePropertyPixelWidth] as? NSNumber)?.floatValue, | |
imageHeight = (properties[kCGImagePropertyPixelHeight] as? NSNumber)?.floatValue, | |
data = NSData(contentsOfURL: url) where acceptableSourceType(source) { | |
return ImageOwner(data: data, size: CGSizeMake(CGFloat(imageWidth), CGFloat(imageHeight)), nonce: self.nonce) | |
} |
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 Stub<ArgumentsType> { | |
let argumentsMatcher: ArgumentsType -> Bool | |
init(matcher: ArgumentsType -> Bool) { | |
self.argumentsMatcher = matcher | |
} | |
} | |
var stubs = [Any]() |
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 A { | |
let factory: ()->() | |
var closure: ((b: B)->())? | |
init(factory: ()->()) { | |
self.factory = factory | |
} | |
deinit { |
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 EmbededTableView: UITableView { | |
override func intrinsicContentSize() -> CGSize { | |
layoutIfNeeded() | |
return CGSizeMake(UIViewNoIntrinsicMetric, self.contentSize.height) | |
} | |
override func reloadData() { | |
super.reloadData() | |
invalidateIntrinsicContentSize() |
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 XCTestCase { | |
func fail(expectation: XCTestExpectation?, file: String = __FILE__, line: UInt = __LINE__) { | |
expectation?.fulfill() | |
self.recordFailureWithDescription("Expectation failed: \(expectation)", inFile: file, atLine: line, expected: false) | |
} | |
func fulfill(expectation: XCTestExpectation?, @autoclosure condition: ()->Bool = true, file: String = __FILE__, line: UInt = __LINE__) { | |
guard let expectation = expectation else { return } | |
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 CollectionType where Index: Comparable { | |
subscript(safe index: Index) -> Generator.Element? { | |
guard index >= startIndex && index < endIndex else { | |
return nil | |
} | |
return self[index] | |
} | |
} |
OlderNewer