Skip to content

Instantly share code, notes, and snippets.

View NachoSoto's full-sized avatar

NachoSoto NachoSoto

View GitHub Profile
@NachoSoto
NachoSoto / UniqueElements.swift
Created December 27, 2017 01:28
Example of how to extract unique elements from a sequence in Swift
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] = []
@NachoSoto
NachoSoto / UIAccessibilityTraits+Extensions.swift
Last active March 19, 2019 23:10
Extensions to simplify usage of accessibilityTraits in Swift 4.2:
// 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