Skip to content

Instantly share code, notes, and snippets.

View jandamm's full-sized avatar
🐄

Jan Damm jandamm

🐄
View GitHub Profile
@jandamm
jandamm / ExampleCraftSwift.swift
Last active March 21, 2016 13:37
InVision Craft-Plugin Styles for Swift
//
// Example.swift
//
// Created by Jan Dammshäuser
// Copyright © 2016 Jan Dammshäuser. All rights reserved.
//
import UIKit
class ExampleVC: UIViewController {
@jandamm
jandamm / SafeZip2Sequence.swift
Last active January 21, 2018 21:36
This is a Gist for a blogpost I did.
/// In contrast to the Swift Zip2Sequence this type will not omit values that don't have a partner due to Sequence length mismatch.
/// The Iterator will iterate over `SafeZip2Sequence.Value`.
public struct SafeZip2Sequence<Sequence1: Sequence, Sequence2: Sequence> {
fileprivate let sequence1: Sequence1
fileprivate let sequence2: Sequence2
}
extension SafeZip2Sequence: Sequence {
/// An iterator for `SafeZip2Sequence`.
public struct Iterator {
@jandamm
jandamm / Protocol.swift
Last active January 21, 2018 12:12
Static vs dynamic dispatch for protocol extensions
protocol A {
func a()
}
extension A {
func a() {
print("protocol extension a")
}
func b() {
import UIKit
func returnsNil() -> UIView? {
weak var view: UIView? = UIView()
return view
}
func returnsView1() -> UIView? {
weak var view: UIView?
view = UIView()
protocol Test {
associatedtype Output
func test() -> Output
}
struct A: Test {
typealias Output = Void
func test() {
print("aa")
}
import Foundation
// MARK: - Library
public extension UserDefaults {
struct Key<Value> {
let key: String
public init(key: String) {
self.key = key