This file contains hidden or 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 | |
enum SomeError: Error { | |
case foo, bar, baz, unknown | |
} | |
struct SDK { | |
func simpleAsync() async -> Int { | |
try? await Task.sleep(seconds: 2) | |
return 42 |
This file contains hidden or 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
class MyCell: UITableViewCell { | |
let titleLabel = UILabel() | |
let subtitleLabel = UILabel() | |
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | |
super.init(style: style, reuseIdentifier: reuseIdentifier) | |
} | |
required init?(coder: NSCoder) { nil } | |
This file contains hidden or 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 Publisher { | |
func asResult() -> AnyPublisher<Result<Output, Failure>, Never> { | |
return map(Result.success) | |
.catch { Just(Result.failure($0)) } | |
.eraseToAnyPublisher() | |
} | |
} | |
extension Publisher { | |
func values<S, F: Error>() -> AnyPublisher<S, Never> where Output == Result<S, F>, Failure == Never { |
This file contains hidden or 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 AnyCodingKey: CodingKey { | |
var stringValue: String | |
var intValue: Int? | |
init(stringValue: String) { | |
self.stringValue = stringValue | |
self.intValue = nil | |
} | |
init(intValue: Int) { |
This file contains hidden or 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
/* | |
Cory Benfield - Building State Machines in Swift | |
https://www.youtube.com/watch?v=7UC7OUdtY_Q | |
What is a Finite State Machine? | |
- Structured way to represent computation | |
- System can be in one of a finite number of states at any time | |
- Reacts to inputs by changing state, and optionally producing a side effect | |
- Deterministic and nondeterministic flavors | |
- Simple model of computation: easy to understand |
This file contains hidden or 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
Top: 35 | |
Sides: 20 | |
Corner Radius: 10 | |
(lldb) po tableView.cellForRow(at: .init(row: 0, section: 0))?.frame | |
▿ Optional<CGRect> | |
▿ some : (0.0, 35.0, 374.0, 44.0) | |
▿ origin : (0.0, 35.0) | |
- x : 0.0 | |
- y : 35.0 |
This file contains hidden or 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 | |
public protocol NetworkLoggable { | |
func log<T: CustomStringConvertible>( | |
label: String, | |
value: T?, | |
level: NetworkLogger, | |
function: StaticString, | |
line: UInt, | |
file: String |
This file contains hidden or 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
@propertyWrapper | |
struct CodableUserDefault<Value: Codable> { | |
let key: String | |
var wrappedValue: Value? { | |
get { | |
UserDefaults.standard.data(forKey: key).flatMap { | |
try? JSONDecoder().decode(Value.self, from: $0) | |
} | |
} |
This file contains hidden or 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 PlaygroundSupport | |
import XCTest | |
extension Array { | |
/// Remove duplicates based on `KeyPath` | |
/// - Parameter keyPath: Property to determine uniqueness | |
/// - Returns: `Array` of unique `Elements` based on `keyPath` argument | |
/// - Complexity Time: O(n) / Space: O(n) | |
func removingDuplicates<T: Hashable>(by keyPath: KeyPath<Element, T>) -> Self { |