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 | |
func randomNumbers(_ count: Int, totalling sum: Int) -> [Int] { | |
let randomOffsets = (0 ..< count - 1).map { _ in Int.random(in: 1 ..< sum) } | |
let range = ([0] + randomOffsets + [sum]).sorted() | |
var values: [Int] = [] | |
for i in 0 ... count - 1 { |
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 | |
let cast = ["🚶♂️🚶🏻♂️🚶🏼♂️🚶🏽♂️🚶🏾♂️🚶🏿♂️🚶♀️🚶🏻♀️🚶🏼♀️🚶🏽♀️🚶🏾♀️🚶🏿♀️"] | |
var string = "Virtual #WWDC20 queue:\n" | |
while string.count <= 280 { | |
string.append(cast.randomElement()!) | |
} |
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
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
@_functionBuilder | |
struct UIViewBuilder { | |
static func buildBlock(_ views: UIView...) -> [UIView] { | |
return views | |
} |
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 | |
import ObjectiveC | |
private var subclassCounts: [String: Int] = [:] | |
func GenerateDynamicSubclass<T: NSObject>(of class: T.Type) -> T.Type! { | |
let oldClassName = NSStringFromClass(`class`) as String | |
var subclassCount = subclassCounts[oldClassName] ?? 0 | |
let className = "\(oldClassName)_DynamicSubclass_\(subclassCount)" | |
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 | |
import MapKit | |
extension Locale { | |
var usesMilesForDistanceFormatting: Bool { | |
guard usesMetricSystem else { return true } | |
let miles = Measurement(value: 42, unit: UnitLength.miles) | |
let kilometers = miles.converted(to: .kilometers) |
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
// | |
// FetchPublisher.swift | |
// [REDACTED] | |
// | |
// Created by Jeff Kelley on 6/20/19. | |
// Copyright © 2019 Jeff Kelley. All rights reserved. | |
// | |
import CoreData | |
import Combine |
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 | |
func paddedZip<T, U, Sequence1, Sequence2>( | |
_ sequence1: Sequence1, | |
_ sequence2: Sequence2 | |
) -> Zip2Sequence<[T?], [U?]> where | |
Sequence1 : Sequence, Sequence1.Element == T, | |
Sequence2 : Sequence, Sequence2.Element == U { | |
var array1: [T?] = [] | |
var array2: [U?] = [] |
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 KeyedDecodingContainer { | |
/// An item that cannot be decoded. Used in `compactDecode(arrayOf:forKey:)` | |
/// to represent items that could not be decoded. | |
private struct UndecodableItem: Decodable {} | |
/// Attempts to decode an array of type `T`. If an individual item in the | |
/// array fails to decode, these errors are not passed on to the caller; | |
/// instead, they are not included in the final 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
GYB_PATH="${SRCROOT}/Vendor/gyb/gyb" | |
function gyb { | |
file=$1 | |
if [ ${file: -4} == ".gyb" ]; then | |
"${GYB_PATH}" --line-directive '' -o "${file%.gyb}" "$file"; | |
fi | |
} | |
if [ $SCRIPT_INPUT_FILE_COUNT -ne 0 ]; then |
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
//: Advanced Dates and Times in Swift | |
import Foundation | |
#if os(macOS) | |
import PlaygroundSupport | |
import UserNotifications | |
#endif | |
// Date Intervals |
NewerOlder