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 keyframes.swift
//
// ContentView.swift
// KeyFrameAnimation
//
// Created by Chris Eidhof on 21.10.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import SwiftUI
View shake.swift
//
// ContentView.swift
// Shake
//
// Created by Chris Eidhof on 01.10.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
View animationcurves.swift
//
// ContentView.swift
// AnimationTimingCurve
//
// Created by Chris Eidhof on 25.09.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
View hello.swift
struct ContentView: View {
@State var prop: Bool = true
var body: some View {
VStack {
Rectangle()
.fill(prop ? Color.red : Color.green)
.frame(width: prop ? 100 : 300, height: prop ? 50 : 200)
.animation(.linear)
Spacer()
Toggle(isOn: $prop, label: { Text("Toggle") })
View collectionview.swift
//
// ContentView.swift
// CollectionView
//
// Created by Chris Eidhof on 20.08.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
View objcioarrow.swift
//
// ContentView.swift
// SwiftTalkAnimationLoader
//
// Created by Chris Eidhof on 30.07.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
@chriseidhof
chriseidhof / routing.swift
Last active Aug 24, 2019
routing_attempt_n
View routing.swift
import Foundation
struct Episode: Codable { }
struct EpisodeDetail: Codable { }
// episodes.json returns an [Episode]
// /episodes/foo should be (String) -> EpisodeDetail
enum Either<A, B> {
case left(A)
@chriseidhof
chriseidhof / understanding.md
Created Jul 12, 2019
Understanding SwiftUI
View understanding.md

My understanding of SwiftUI

  • The main advantage of SwiftUI over UIKit is to write both your initial UI rendering as well as any updates to your UI in one go.
  • On a very abstract level, this is similar to TEA, but practically, it's quite different: updates in SwiftUI are incremental, and for many things there's no diffing necessary.

In SwiftUI, you define your views as structs that conform to View. The View protocol has a single requirement: you need to implement body, a computed property that returns another type conforming to View.

Just like normal structs in Swift, you can use properties anywhere inside your View. However, unlike normal structs, some properties are special. Specifically, properties that are defined using the property wrappers EnvironmentObject, ObjectBinding, State (and some others). When SwiftUI renders the body, it will subscribe to these properties. When these properties change, they send a notification, and SwiftUI will re-render the necessary parts. I call thes

View imagemanager.swift
final fileprivate class Weak<A: AnyObject> {
weak var value: A?
init(_ value: A) {
self.value = value
}
}
final class ImageManager {
fileprivate var values: [URL:Weak<Resource<UIImage>>] = [:]
@chriseidhof
chriseidhof / subscriptions.swift
Last active Jul 9, 2019
SwiftUI Problem - FB6571851
View subscriptions.swift
import SwiftUI
import Combine
final class Test: BindableObject {
let subject = PassthroughSubject<(), Never>()
private(set) var didChange: AnyPublisher<(), Never> = Publishers.Empty().eraseToAnyPublisher()
var value: String = "Hi"
init() {
print("Init")
You can’t perform that action at this time.