Skip to content

Instantly share code, notes, and snippets.

Chris Eidhof chriseidhof

Block or report user

Report or block chriseidhof

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View helpers.swift
struct <#MyView#>: View {
var body: some View {
<#body#>
}
}
extension View {
func geometryPreference<P: PreferenceKey>(_ key: P.Type, value: @escaping (GeometryProxy) -> P.Value) -> some View {
overlay(GeometryReader { proxy in
Color.clear.preference(key: P.self, value: value(proxy))
View relative.swift
extension View {
func vertical(_ key: VerticalAlignment, relative: CGFloat) -> some View {
self.alignmentGuide(key, computeValue: { $0.height * relative })
}
func overlay<V: View>(alignment: Alignment, relative: UnitPoint = .center, _ other: V) -> some View {
self
.alignmentGuide(alignment.horizontal, computeValue: { $0.width * relative.x })
.alignmentGuide(alignment.vertical, computeValue: { $0.height * relative.y })
.overlay(other, alignment: alignment)
View contentview.swift
//
// ContentView.swift
// Clocks
//
// Created by Chris Eidhof on 21.02.20.
// Copyright © 2020 objc.io. All rights reserved.
//
import SwiftUI
View minmaxideal.swift
//
// ContentView.swift
// QuickCheckTests
//
// Created by Chris Eidhof on 20.02.20.
// Copyright © 2020 objc.io. All rights reserved.
//
import SwiftUI
@chriseidhof
chriseidhof / racepace.swift
Created Feb 19, 2020
Race Pace Calculator
View racepace.swift
//
// ContentView.swift
// RunningPaceCalculator
//
// Created by Chris Eidhof on 19.02.20.
// Copyright © 2020 Chris Eidhof. All rights reserved.
//
import SwiftUI
View state.swift
struct MyView: View {
@State var text: String = "hello"
var body: some View {
TextField("title", text: $text)
}
}
struct ContentView: View {
@State var toggled: Bool = false
var body: some View {
View ContentView.swift
import SwiftUI
extension View {
func assert(size: CGSize) -> some View {
self.overlay(GeometryReader { proxy in
Group {
if size == proxy.size {
Color.clear
} else {
Color.red.opacity(0.5)
View elmy.swift
//
// ContentView.swift
// Store
//
// Created by Chris Eidhof on 05.02.20.
// Copyright © 2020 Chris Eidhof. All rights reserved.
//
import SwiftUI
View script.swift
import SwiftSyntax
import SwiftSemantics
import Foundation
let source = try! String(contentsOf: URL(fileURLWithPath: "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64e.swiftinterface"))
var collector = DeclarationCollector()
let tree = try SyntaxParser.parse(source: source)
tree.walk(&collector)
View tobias.swift
import SwiftUI
final class Ticks: ObservableObject {
@Published var seconds: Int = 58
func start() {
Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [unowned self] _ in
withAnimation(.easeInOut) { self.seconds += 1 }
if self.seconds == 60 {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .milliseconds(350)) {
You can’t perform that action at this time.