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
// Extensions to simplify usage of accessibilityTraits in Swift 4.2: | |
public func |= (traits: inout UIAccessibilityTraits, other: [UIAccessibilityTraits]) { | |
for o in other { | |
traits |= o | |
} | |
} | |
public func |= (traits: inout UIAccessibilityTraits, other: UIAccessibilityTraits) { | |
// From: https://swift.org/migration-guide-swift4.2/#known-migration-issues |
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 | |
extension Sequence { | |
// Extension on Sequence allows us to use this method on Arrays, Maps, Sets, etc. | |
func uniqueElements<Index: Hashable>(for indexer: (Element) -> Index) -> [Element] { | |
// Keep track of what we've already seen in a Set, | |
// which allows us to query for elements efficiently. | |
var seenElements: Set<Index> = [] | |
var result: [Element] = [] |
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 Cartography // https://github.com/robb/Cartography | |
/** | |
This is an example of self sizing `UICollectionView` cells using AutoLayout, | |
where the width of cells is always the width of the parent, to mimic `UITableView`. | |
*/ | |
fileprivate let items: [String] = (0..<100) | |
.map { _ in Lorem.sentences(Int.random(min: 1, max: 8)) } // Using https://github.com/lukaskubanek/LoremSwiftum/blob/master/Sources/LoremSwiftum.swift |
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
Test Suite 'All tests' started at 2017-03-28 11:27:46.053 | |
Test Suite 'Quick.framework' started at 2017-03-28 11:27:46.055 | |
Test Suite 'Quick.framework' passed at 2017-03-28 11:27:46.055. | |
Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds | |
Test Suite 'APITests.xctest' started at 2017-03-28 11:27:46.056 | |
Test Suite 'WebURLParserSpec' started at 2017-03-28 11:27:46.057 | |
Test Case '-[APITests.WebURLParserSpec Card_graph_URLs__parses_url_with_all_data]' started. | |
================================================================= | |
==32504==ERROR: AddressSanitizer: heap-use-after-free on address 0x60600028a8b0 at pc 0x0001207f1970 bp 0x7fff529ebf30 sp 0x7fff529ebf28 | |
WRITE of size 8 at 0x60600028a8b0 thread T0 |
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
// https://twitter.com/davedelong/status/701621040015810560: @NachoSoto is there a way to take a # of SignalProducer<U,E> and turn them in to SignalProducer<[U], E>? Like combineLatest but w/o tuples | |
let signals: [SignalProducer<T, E>] | |
let result: SignalProducer<[T], E> = | |
SignalProducer(values: signals) // create a producer that emits all signals. | |
.flatten(.Merge) // merge all values that they emit. | |
.collect() // collect all values into an array. |
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
// | |
// Signal+Extensions.swift | |
// Khan Academy | |
// | |
// Created by Nacho Soto on 10/1/15. | |
// Copyright © 2015 Khan Academy. All rights reserved. | |
// | |
import ReactiveCocoa |
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
protocol ValidatorType { | |
typealias ValidatedType | |
func isValid(object: ValidatedType) -> Bool | |
} | |
// You might want to make it a reference type, depending on your case. | |
struct AnyValidator<T>: ValidatorType { | |
private let validatorBlock: (T) -> Bool | |
init<V: ValidatorType where V.ValidatedType == T>(validator: V) { |
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
# Using https://github.com/Anviking/Decodable as example: | |
xcodebuild -sdk appletvsimulator -project Decodable.xcodeproj -configuration Release -scheme Decodable-tvOS ONLY_ACTIVE_ARCH=NO clean build | |
# This fails with http://www.openradar.me/22993940 |
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
var testArray: [Int] = [] | |
func modify(action: [Int] -> [Int]) { | |
testArray = action(testArray) | |
} | |
for _ in 0..<50 { | |
modify { array in | |
var array = array | |
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
func f(a: Bool, b: Bool) { | |
switch (a, b) { | |
case (false, false): | |
break | |
case (false, true): | |
break | |
case (true, false): | |
break | |
case (true, true): | |
break |
NewerOlder