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 UIVisualEffectView { | |
private var filterLayer: CALayer? { | |
return layer.sublayers?.first | |
} | |
private var blurFilter: NSObject? { | |
return filterLayer? | |
.filters?.flatMap({ $0 as? NSObject }) | |
.first(where: { $0.value(forKey: "name") as? String == "gaussianBlur" }) |
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 Stylish: class { | |
func updateStyle() | |
} | |
public class StyleProxy<S: Stylish>: NSObject { | |
fileprivate override init() { } | |
} | |
private class StyleProxyView<S: Stylish>: UIView { | |
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 final class Box<T> { | |
public let value: T | |
public init(value: T) { | |
self.value = value | |
} | |
} | |
public final class NSCodingBox<T: Coding>: NSObject, NSCoding { | |
public let value: T | |
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
/* | |
Xcode 8 beta 6 | |
Apple Swift version 3.0 (swiftlang-800.0.43.6 clang-800.0.38) | |
Target: x86_64-apple-macosx10.9 | |
*/ | |
struct Generic<A, B> {} | |
//if typealias is defined inside the concrete type it works: | |
class SomeClass { |
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] | |
} | |
} |
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
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
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 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
//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) | |
} |