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 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)) {
View orview.swift
//
// ContentView.swift
// OrView
//
// Created by Chris Eidhof on 07.11.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
View bars.swift
//
// ContentView.swift
// Bars
//
// Created by Chris Eidhof on 17.12.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import SwiftUI
View diagrams.swift
//
// Diagrams.swift
// DiagramsSample
//
// Created by Chris Eidhof on 16.12.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import SwiftUI
View state-restoration.swift
struct Nested: View {
@State var counter = 0
init() {
print("Init")
}
var body: some View {
Button(action: { self.counter += 1 }, label: {
Text("Tap me! \(counter)")
})
}
@chriseidhof
chriseidhof / sample.swift
Last active Feb 16, 2020
View Inspection
View sample.swift
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
}
}
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {
You can’t perform that action at this time.