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 GameplayKit | |
struct DeterministicRandomNumberGenerator: RandomNumberGenerator { | |
private let randomSource: GKMersenneTwisterRandomSource | |
init(seed: UInt64) { | |
randomSource = GKMersenneTwisterRandomSource(seed: seed) | |
} | |
mutating func next() -> UInt64 { |
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 { | |
func grouping(isMember: (SubSequence, Element) throws -> Bool) rethrows -> [SubSequence] { | |
var result: [SubSequence] = [] | |
var start = self.startIndex | |
for end in self.indices.dropFirst() { | |
let slice = self[start...end] | |
if try !isMember(slice, self[end]) { | |
result.append(self[start..<end]) | |
start = end |
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 SwiftUI | |
protocol DeferedTask { | |
associatedtype Success | |
func run() async throws -> Success | |
} | |
struct ResultView<T: DeferedTask, ID: Equatable, Content: View>: View { | |
var task: T | |
var id: KeyPath<T, ID> |
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 SwiftUI | |
import PhotosUI | |
struct LimitedLibraryPicker: UIViewControllerRepresentable { | |
@Binding var isPresented: Bool | |
func makeUIViewController(context: Context) -> UIViewController { | |
.init() | |
} | |
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 SwiftUI | |
struct OuterView: View { | |
@State var count: Int = 0 | |
var body: some View { | |
VStack { | |
MiddleView(count: $count) | |
.onAppear { | |
count += 100 |
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 SwiftUI | |
struct ActionDispatch<Action, Content: View>: View { | |
@ViewBuilder var content: (@escaping (Action) -> ActionResult) -> Content | |
@State var handler: ActionHandler<Action> = .unhandled | |
// ^use @Box here instead of @State here to avoid the extra re-rendering: https://gist.github.com/JadenGeller/b6ce5db2470aeabcf2f8e936cb3a5725 | |
init(_ type: Action.Type, content: @escaping (@escaping (Action) -> ActionResult) -> Content) { | |
self.content = content | |
} |
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
@propertyWrapper | |
struct Box<T> { | |
class Storage { | |
var value: T | |
init(_ value: T) { | |
self.value = value | |
} | |
} | |
private let storage: Storage |
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 SwiftUI | |
import WebKit | |
struct WebView: NSViewRepresentable { | |
var url: URL | |
class Coordinator: NSObject, WKNavigationDelegate { | |
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in | |
if complete != 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
struct ScanSequence<Base: Sequence, Result>: Sequence { | |
let base: Base | |
let first: Result | |
let next: (Result, Base.Element) -> Result | |
func makeIterator() -> PrependIterator<ScanIterator<Base.Iterator, Result>> { | |
.init(base: .init(base: base.makeIterator(), previous: first, combine: next), first: first) | |
} | |
} |
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 SwiftUI | |
import simd | |
struct Rotation3DEffect: GeometryEffect { | |
var angle: Angle | |
var axis: (x: CGFloat, y: CGFloat, z: CGFloat) | |
var anchor: UnitPoint = .center | |
var anchorZ: CGFloat = 0 | |
var focalLength: CGFloat | |