Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

//
// ContentView.swift
// OverlayTest
//
// Created by Chris Eidhof on 26.09.22.
//
import SwiftUI
struct ContentView: View {
import SwiftUI
struct Light: View {
var body: some View {
Circle()
.overlay(rings)
.overlay(
Circle()
.fill(gradient)
.alignmentGuide(VerticalAlignment.center, computeValue: { $0.height/10 })
@chriseidhof
chriseidhof / ContentView.swift
Last active March 27, 2024 19:14
Variadic Views
import SwiftUI
struct MyValue: _ViewTraitKey {
static var defaultValue: Int = 0
}
extension View {
func myValue(_ value: Int) -> some View {
_trait(MyValue.self, value)
}
//
// ContentView.swift
// Shared
//
// Created by Chris Eidhof on 05.05.22.
//
import SwiftUI
struct ContentView: View {
//
// ContentView.swift
// Shared
//
// Created by Chris Eidhof on 16.04.22.
//
import SwiftUI
struct Jump: AnimatableModifier {
import SwiftUI
extension CGPoint {
static func *(lhs: Self, rhs: CGFloat) -> Self {
.init(x: lhs.x * rhs, y: lhs.y * rhs)
}
}
// Idea: https://www.framer.com/showcase/project/lo2Qka8jtPXrjzZaPZdB/
import SwiftUI
let url = URL(string: "https://www.objc.io/images/books/thinking-in-swiftui/thinking-in-swiftui-hero-original_216a663.png")!
struct ContentView: View {
var image: some View {
AsyncImage(url: url, content: { image in
image
.resizable()
.aspectRatio( contentMode: .fit)
import SwiftUI
struct DetailView: View {
@Binding var showDetail: Bool
var body: some View {
List {
NavigationLink("detail", isActive: $showDetail) {
Text("Detail")
}
@chriseidhof
chriseidhof / AsyncZipped.swift
Last active October 23, 2023 20:41
Async Zipped
/*
Make sure to compile this with the following flags:
-Xfrontend -warn-concurrency -Xfrontend -enable-actor-data-race-checks
*/
extension AsyncIteratorProtocol {
func newAndNext() async throws -> (Self, Element)? {
@chriseidhof
chriseidhof / gist.swift
Last active December 6, 2021 05:29
AsyncZipped
struct AsyncZippedSequence<L, R>: AsyncSequence where L: AsyncSequence, R: AsyncSequence {
typealias Element = (L.Element, R.Element)
var l: L
var r: R
func makeAsyncIterator() -> AsyncZippedIterator<L.Element, R.Element> {
AsyncZippedIterator(l, r)
}
}