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
@chriseidhof
chriseidhof / ob-swiftui.el
Last active May 25, 2020 — forked from xenodium/ob-swiftui.el
Preview SwiftUI layouts using Emacs org blocks
View ob-swiftui.el
(use-package org
:hook ((org-mode . org-display-inline-images))
:config
(use-package ob
:bind (:map org-mode-map
("C-c C-c" . org-ctrl-c-ctrl-c))
:config
(use-package ob-swift
@chriseidhof
chriseidhof / wrapper.swift
Created May 21, 2020
NSBrowser Delegate Wrapper
View wrapper.swift
import Cocoa
// Insipired by http://dcandi.com/post/cocoa-filesystem-browser/
extension URL {
var isDirectory: Bool {
return (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false
}
var fileIcon : NSImage {
View boilerplate.swift
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
View TextAlert.swift
//
// ContentView.swift
//
// Created by Chris Eidhof on 20.04.20.
// Copyright © 2020 objc.io. All rights reserved.
//
import SwiftUI
import UIKit
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 {
You can’t perform that action at this time.