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 ContentView: View { | |
@State var scrollOffset: CGPoint = .zero | |
var body: some View { | |
ObservableScrollView { | |
Text("Hello, world!") | |
.foregroundColor(self.scrollOffset.y == 0 ? .blue : .red) | |
} | |
.onScroll { self.scrollOffset = $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
public enum NilOrdering { | |
case first, last | |
} | |
public enum SortOrdering { | |
case ascending, descending | |
} | |
public extension Sequence { | |
func sorted(on accessor: (Element) -> some Comparable, ordering: SortOrdering = .ascending) -> [Element] { |
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
UIFont.familyNames.forEach({ familyName in | |
let fontNames = UIFont.fontNames(forFamilyName: familyName) | |
print(familyName, fontNames) | |
}) |
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 Security | |
private let DataKey = "MyDataKey" | |
/** | |
* The KeychainResult class wraps an OSStatus that is returned from a keychain action. It vends KeychainErrors. | |
*/ | |
struct KeychainResult { | |
let keychainError: OSStatus |
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 BidirectionalCollection { | |
func makeBidirectionalIterator() -> BidirectionalIterator<Self, Index> { | |
return BidirectionalIterator<Self, Index>(collection: self) | |
} | |
} | |
let a = [1, 2, 3, 4] |
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 AsyncHTTPClient | |
import Foundation | |
struct ServerSentEvent { | |
let name: String | |
let data: String | |
init(_ substring: Substring) { | |
let lines = substring.split(whereSeparator: \.isNewline) | |
self.name = String(lines |
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
// | |
// ContentView.swift | |
// DependentEnvironment | |
// | |
// Created by Soroush Khanlou on 3/27/23. | |
// | |
import SwiftUI | |
struct Inner: View { |
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 BundleVersion: Comparable { | |
let tuple: (Int, Int, Int) | |
init(string: String) { | |
let numbers = string.split(separator: ".").compactMap({ Int($0) }) | |
let major = numbers.count >= 1 ? numbers[0] : 0 | |
let minor = numbers.count >= 2 ? numbers[1] : 0 | |
let patch = numbers.count >= 3 ? numbers[2] : 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
protocol State {} | |
struct Transition<From: State, To: State> { | |
let transition: () -> To | |
} | |
struct Machine<CurrentState: State> { | |
var state: CurrentState | |
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
// | |
// SKSerialInputStream.h | |
// inputstream | |
// | |
// Created by Soroush Khanlou on 11/4/18. | |
// Copyright © 2018 Soroush Khanlou. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> |
NewerOlder