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 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 / routing.swift
Last active Aug 24, 2019
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 /
Created Jul 12, 2019
Understanding SwiftUI

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 / 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() {
View RemoteValue.swift
import Foundation
import SwiftUI
import Combine
import TinyNetworking
final class RemoteValue<A>: BindableObject {
let didChange = MyPublisher()
let endpoint: Endpoint<A>
var value: A? {
didSet {
View LazyView.swift
struct LazyView<Content: View>: View {
let build: () -> Content
init(_ build: @autoclosure @escaping () -> Content) { = build
var body: Content {
View sample.swift
// AppDelegate.swift
// GithubInfo
// Created by Chris Eidhof on 25.06.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
import UIKit
import SwiftUI
chriseidhof / swiftui.swift
Last active Jun 18, 2019
SwiftUI - macOS
View swiftui.swift
import AppKit
import Combine
import CoreFoundation
import CoreGraphics
import CoreText
import Darwin
import Foundation
import SwiftUI
import os.log
import os
You can’t perform that action at this time.