Skip to content

Instantly share code, notes, and snippets.

@darrarski
darrarski / FormattedTextField.swift
Last active April 16, 2024 13:14
SwiftUI FormattedTextField - TextField with custom display/edit formatters
import SwiftUI
public struct FormattedTextField<Formatter: TextFieldFormatter>: View {
public init(_ title: String,
value: Binding<Formatter.Value>,
formatter: Formatter) {
self.title = title
self.value = value
self.formatter = formatter
}
@jamesmacfie
jamesmacfie / README.md
Created October 22, 2019 02:53
iTerm 2 - script to change theme depending on Mac OS dark mode

How to use

In iTerm2, in the menu bar go to Scripts > Manage > New Python Script

Select Basic. Select Long-Running Daemon

Give the script a decent name (I chose auto_dark_mode.py)

Save and open the script in your editor of choice.

@fitomad
fitomad / KeyboardResponder.swift
Created November 22, 2019 19:23
Manage iOS keyboard presentation and dismiss with your SwiftUI views.
//
// KeyboardResponder.swift
// MoveMAD
//
// Created by Adolfo Vera Blasco on 19/11/2019.
// Copyright © 2019 desappstre {eStudio}. All rights reserved.
//
import SwiftUI
@IsaacXen
IsaacXen / README.md
Last active May 18, 2024 19:48
(Almost) Every WWDC videos download links for aria2c.
// 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))
@Amzd
Amzd / View+NSCursor.swift
Last active February 9, 2024 17:34
Set the cursor that is displayed when hovering a View. (macOS, SwiftUI)
import SwiftUI
extension View {
/// https://stackoverflow.com/a/61985678/3393964
public func cursor(_ cursor: NSCursor) -> some View {
self.onHover { inside in
if inside {
cursor.push()
} else {
NSCursor.pop()
@hmlongco
hmlongco / Themes.swift
Last active January 10, 2023 06:54
Themes for SwiftUI
struct Colors {
let primary: Color
}
struct Fonts {
let body: Font
}
class Theme: ObservableObject {
let color: Colors
@humblehacker
humblehacker / kotlin-inject-composable-viewmodel.md
Last active March 17, 2022 13:56
Injecting view models into Composable functions with kotlin-inject

According to the docs, the non-DI way to associate an view model with an @Composable is via the viewModel() function from androidx.lifecycle.viewmodel.compose.viewModel, like this:

@Composable
fun ProfileScreen(val viewModel: ProfileViewModel = viewModel() {
  ...

But if your view model requires dependencies, you have to pass a subclass of ViewModelProvider.Factory that holds the dependency and knows how to construct the view model for you. Like this:

@Evian-Zhang
Evian-Zhang / find_sdk_root.sh
Created June 15, 2022 09:03
Proper way to handle "ld: library not found for -lSystem" in macOS
SDKROOT=`/usr/bin/xcrun --show-sdk-path -sdk macosx`
as test.s -o test.o
ld test.o -lSystem -L $(SDKROOT)/usr/lib -o test
@czottmann
czottmann / Format current file with swiftformat.scpt
Last active December 30, 2022 19:04
Xcode helper: SwiftFormat the currently focussed doc w/o losing undo history
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
-- # This script formats the currently open and focussed Swift file
-- # using SwiftFormat. It does so *without* resetting the editor's
-- # undo history.
-- #
-- # Version 2022-12-30.01
-- #
-- # Author: Carlo Zottmann