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 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")
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) {
self.build = build
}
var body: Content {
build()
}
}
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
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
View swiftui.swift
import Combine
import CoreFoundation
import CoreGraphics
import CoreText
import Darwin
import Foundation
import SwiftUI
import UIKit
import os.log
import os
View Bindable.swift
/// Similar to a `Binding`, but this is also observable/dynamic.
@propertyDelegate
@dynamicMemberLookup
final class Derived<A>: BindableObject {
let didChange = PassthroughSubject<A, Never>()
fileprivate var cancellables: [AnyCancellable] = []
private let get: () -> (A)
private let mutate: ((inout A) -> ()) -> ()
init(get: @escaping () -> A, mutate: @escaping ((inout A) -> ()) -> ()) {
self.get = get
View AnimatedIndicator
//
// ContentView.swift
// ActivityIndicator
//
// Created by Chris Eidhof on 11.06.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
import Combine
View ProgressIndicator.swift
struct ProgressIndicator: NSViewRepresentable {
@Binding var style: NSProgressIndicator.Style
func makeNSView(context: NSViewRepresentableContext<ProgressIndicator>) -> NSProgressIndicator {
let result = NSProgressIndicator()
result.isIndeterminate = true
result.startAnimation(nil)
return result
}
You can’t perform that action at this time.