Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
extension CGPoint {
static func *(lhs: Self, rhs: CGFloat) -> Self {
.init(x: lhs.x * rhs, y: lhs.y * rhs)
}
}
// Idea: https://www.framer.com/showcase/project/lo2Qka8jtPXrjzZaPZdB/
@chriseidhof
chriseidhof / AsyncZipped.swift
Last active October 23, 2023 20:41
Async Zipped
/*
Make sure to compile this with the following flags:
-Xfrontend -warn-concurrency -Xfrontend -enable-actor-data-race-checks
*/
extension AsyncIteratorProtocol {
func newAndNext() async throws -> (Self, Element)? {
@chriseidhof
chriseidhof / sample.swift
Last active October 17, 2023 15:36
Networking
//
// AppDelegate.swift
// GithubInfo
//
// Created by Chris Eidhof on 25.06.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import UIKit
import SwiftUI
@chriseidhof
chriseidhof / tableviews.swift
Last active October 15, 2023 20:56
trySwift
import UIKit
// If you enjoyed this talk (video link will be up soon), then you might also enjoy our book Advanced Swift: http://www.objc.io/books/advanced-swift
struct Person {
let name: String
let city: String
}
let people = [
@chriseidhof
chriseidhof / helloworld.swift
Created May 28, 2018 13:58
NIO Hello World
import Foundation
import NIO
import NIOHTTP1
// Inspired/parts copied from http://www.alwaysrightinstitute.com/microexpress-nio/
final class HelloHandler: ChannelInboundHandler {
typealias InboundIn = HTTPServerRequestPart
func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
import Cocoa
import MASShortcut
func pow() {
let rect = NSScreen.mainScreen()?.frame
let window = NSWindow(contentRect: rect!, styleMask: NSBorderlessWindowMask, backing: .Buffered, `defer`: false)
window.backgroundColor = NSColor.clearColor()
window.opaque = false
window.alphaValue = 1
window.makeKeyAndOrderFront(NSApplication.sharedApplication())
//
import SwiftUI
struct MyTextEditor: NSViewRepresentable {
@Binding var text: String
final class Coordinator: NSObject, NSTextViewDelegate {
var text: Binding<String>
//
import SwiftUI
struct ContentView: View {
@State private var toggle = true
@Namespace private var ns
var body: some View {
let box = Rectangle()
.fill(.tertiary)
@chriseidhof
chriseidhof / SimpleRepresentable.swift
Last active September 8, 2023 07:12 — forked from vincefried/SimpleRepresentable.swift
A small demonstration of how I would like a way to modify a wrapped UIView.
import UIKit
import SwiftUI
struct ContentView2: View {
var body: some View {
VStack {
SimpleRepresentable(text: "Test")
}
}
}
//
// main.swift
// ExtensibleEffects
//
// Created by Chris Eidhof on 02.01.18.
// Copyright © 2018 objc.io. All rights reserved.
//
import Foundation