Skip to content

Instantly share code, notes, and snippets.

View BottomSheet.swift
//
// ContentView.swift
// Shared
//
// Created by Chris Eidhof on 05.05.22.
//
import SwiftUI
struct ContentView: View {
View Jump.swift
//
// ContentView.swift
// Shared
//
// Created by Chris Eidhof on 16.04.22.
//
import SwiftUI
struct Jump: AnimatableModifier {
View FavoriteButton.swift
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/
View BrokenAsyncImage.swift
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)
View Navigation.swift
import SwiftUI
struct DetailView: View {
@Binding var showDetail: Bool
var body: some View {
List {
NavigationLink("detail", isActive: $showDetail) {
Text("Detail")
}
View AsyncZipped.swift
/*
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)? {
View gist.swift
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)
}
}
View is_this_a_bug.swift
import SwiftUI
struct ContentView: View {
@State var cond = false
var body: some View {
ZStack {
Color.blue
Test(cond: cond).onTapGesture {
withAnimation(.easeInOut(duration: 2)) {
cond.toggle()
View SwiftUI-pipe.swift
import SwiftUI
extension View {
func pipe<R>(@ViewBuilder _ f: (Self) -> R) -> R {
f(self)
}
}
struct ContentView: View {
@State var flag: Bool = false
View Package.swift
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "TomlToYaml",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.executable(