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 SwiftUI | |
for _ in 1...100 { | |
let color = Color( | |
red: .random(in: 0...1), | |
green: .random(in: 0...1), | |
blue: .random(in: 0...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
extension Locale { | |
var defaultTemperatureUnit: UnitTemperature { | |
if #available(iOS 16, *) { | |
return UnitTemperature(forLocale: self, usage: .general) | |
} else { | |
let mCel = Measurement(value: 0, unit: UnitTemperature.celsius) | |
let f = MeasurementFormatter() | |
f.locale = self | |
let s1 = f.string(from: mCel) |
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 XCTest | |
struct WompWomp: Error { | |
} | |
func myThrowingFunction() throws -> Int { | |
throw WompWomp() | |
} |
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 registration = UICollectionView.CellRegistration<CardCollectionViewCell, Card> { cell, indexPath, card in | |
cell.card = card | |
} | |
let dataSource = UICollectionViewDiffableDataSource<Column, Card>( | |
collectionView: collectionView | |
) { collectionView, indexPath, card -> UICollectionViewCell in | |
collectionView.dequeueConfiguredReusableCell( | |
using: registration, | |
for: indexPath, | |
item: card |
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 Let { | |
let x: String? | |
} | |
struct Var { | |
var x: String? | |
} | |
let l1 = Let(x: nil) | |
// let l2 = Let() // not available |
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 MyProtocol { | |
func doThe(thing: String) | |
} | |
extension MyProtocol { | |
func doThe(thing: String = "") { | |
print("protocol") | |
} | |
} |
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
/* | |
Returns the localized label(s) that should be provided by the user to refer to this element. | |
Use this property when the accessibilityLabel is not appropriate for dictated or typed input. | |
For example, an element that contains additional descriptive information in its accessibilityLabel can return a more concise label. | |
The primary label should be first in the array, optionally followed by alternative labels in descending order of importance. | |
If this property returns an empty or invalid value, the accessibilityLabel will be used instead. | |
default == an empty array | |
default on UIKit controls == an array with an appropriate label, if different from accessibilityLabel | |
*/ | |
@available(iOS 13.0, *) |
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 Messages: Decodable { | |
let count: String | |
let messages: [Message] | |
enum CodingKeys: String, CodingKey { | |
case count = "message-count" | |
case messages | |
} |
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 Vector<T> { | |
let size: Int | |
let initialValue: T | |
struct Position: Equatable { | |
let row: Int | |
let column: Int | |
} | |
typealias Matrix = [Position] |
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 Solution<Problem>: Collection { | |
struct Step<T> { | |
let step: T | |
} | |
let steps: [Step<Problem>] | |
var input: Step<Problem> { | |
return steps.first! // safe, as steps will guaranteed to be larger than 0. | |
} |
NewerOlder