defaults write com.apple.dt.Xcode IDEIndexerActivityShowNumericProgress -bool true
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 | |
protocol Component: NSObjectProtocol { | |
var accessibilityTraits: UIAccessibilityTraits { get set } | |
} | |
public final class SpecialComponent: UIView, Component {} | |
let mySpecialComponent: Component = SpecialComponent(frame: .zero) | |
mySpecialComponent.accessibilityTraits = .staticText |
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
struct A: Hashable { } | |
struct B: Hashable { // error: type 'B' does not conform to protocol 'Hashable' | |
let aa: [A] | |
} |
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
#if swift(>=4.1) | |
#else | |
extension Collection { | |
func compactMap<ElementOfResult>( | |
_ transform: (Element) throws -> ElementOfResult? | |
) rethrows -> [ElementOfResult] { | |
return try flatMap(transform) | |
} | |
} | |
#endif |
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
extension Collection where Element == Int, Index == Int { | |
/// Calculates a moving average. | |
/// - Parameter period: the period to calculate averages for. | |
/// - Warning: the supplied `period` must be larger than 1. | |
/// - Warning: the supplied `period` should not exceed the collection's `count`. | |
/// - Returns: a dictionary of indexes and averages. | |
func movingAverage(period: Int) -> [Int: Float] { | |
precondition(period > 1) | |
precondition(count > period) |
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 where Element: Equatable { | |
/// Returns a Boolean value indicating whether every element of the sequence | |
/// is equal to the given element. | |
func containsOnly(_ element: Element) -> Bool { | |
var iterator = self.makeIterator() | |
guard iterator.next() != nil else { return false } | |
return first(where: { $0 != element }) == nil |
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 | |
struct Person: Codable { | |
public let name: String | |
} | |
let person = Person(name: "Bas") | |
let payload = try JSONEncoder().encode(person) | |
let string = String(data: payload, encoding: .utf8) // {"name":"Bas"} | |
let decodedPerson = try JSONDecoder().decode(Person.self, from: payload) // Person(name: "Bas") |
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 | |
class VC: UIViewController { | |
func formatter() -> DateFormatter { | |
struct Formatter { | |
static let f: DateFormatter = { | |
let f = DateFormatter() | |
f.dateStyle = .medium | |
print("I am called just once") | |
return f |
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
let o1nil: Int? = nil | |
let o1: Int? = 1 | |
func switcher(_ a: Int?, _ b: Int?) { | |
switch (a, b) { | |
case (nil, nil): | |
print("nothing") | |
case (let thing?, nil): | |
print("lhs", thing) | |
case (nil, let thing?): |
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 | |
URL(string: "https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch_reading_ease") // nil | |
URL(string: "https://en.wikipedia.org/wiki/Flesch-Kincaid_readability_tests#Flesch_reading_ease") // valid | |
URL(string: "https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch.E2.80.93Kincaid_grade_level") // nil | |
URL(string: "https://en.wikipedia.org/wiki/Flesch-Kincaid_readability_tests#Flesch.E2.80.93Kincaid_grade_level") // valid | |
"https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch_reading_ease" == | |
"https://en.wikipedia.org/wiki/Flesch-Kincaid_readability_tests#Flesch_reading_ease" // false |