Skip to content

Instantly share code, notes, and snippets.

View cgoldsby's full-sized avatar

Chris Goldsby cgoldsby

  • Zattoo, Inc.
  • Zürich, Switzerland
View GitHub Profile
@cgoldsby
cgoldsby / Solution.swift
Last active September 5, 2015 11:32
MakeItCompileChallenge Challenge #4
// I really like this one
// XCode 7.0 beta 6 (7A192o)
typealias D = NonObjectiveCBase
func ~=(left: Any, right: Bool) -> BooleanType {
return true
}
// I really like this one
// XCode 7.0 beta 6 (7A192o)
func ~=(left: Any, right: Bool) -> BooleanType {
return true
}
func +(left: Any, right: Any) -> String {
return ""
@cgoldsby
cgoldsby / XCTestCase+Expectation.swift
Last active June 4, 2021 13:58
XCTestCase extension with boilerplate code for unit testing async functions (waiting for expectations)
//
// AsyncTests.swift
//
import XCTest
// MARK: Async Helper Extension
extension XCTestCase {
struct Service { }
protocol ServiceLocatorProtocol {
func provideService() -> Service
}
struct StructServiceLocator: ServiceLocatorProtocol {
static var sharedInstance = StructServiceLocator()
private init() { }
func provideService() -> Service {
return Service()
}
}
enum EnumServiceLocator: ServiceLocatorProtocol {
case sharedInstance
func provideService() -> Service {
return Service()
}
}
EnumServiceLocator.sharedInstance.provideService()
func ==<T: CollectionType where T.Generator.Element: Equatable>(lhs: T, rhs: T) -> Bool {
return lhs.count == rhs.count && !(zip(lhs, rhs).contains { $0.0 != $0.1 })
}
@cgoldsby
cgoldsby / gradient-playground
Created August 10, 2016 22:08
Gradient Mask v. Gradient Layer
import UIKit
import XCPlayground
import UIKit
final public class GradientView: UIView {
override public class func layerClass() -> AnyClass {
return CAGradientLayer.self
}
One last thing, as a bonus, is we have CATransitions. You’ll notice in a number of these animations that the text transitions between states is in a little bit more of an elegant fashion than our normal set text. Set text is very effective, but when you replace the text within about one frame, it’s very jarring. When you’re fading colors around your text, we really want to consider fading the text as well.
extension CATransition {
static func simpleFade() -> CATransition {
let fadeTransition = CATransition()
fadeTransition.duration = 0.125
fadeTransition.type = kCATransitionFade
fadeTransition.timingFunction = CAMediaTimingFunction(
name: kCAMediaTimingFunctionEaseInEaseOut)
return fadeTransition
@cgoldsby
cgoldsby / miswift-challenge-2.swift
Last active March 18, 2017 13:56
MiSwift Challenge #2 - Linked List
//: Playground - noun: a place where people can play
import Foundation
class Node<T> {
let value: T
var next: Node<T>?
init(value: T) {