Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View krzyzanowskim's full-sized avatar

Marcin Krzyzanowski krzyzanowskim

View GitHub Profile
// Backport SwiftUI.Toggle.init(_:sources:isOn:)
// https://developer.apple.com/documentation/swiftui/toggle/init(_:ison:)-8qx3l
@available(iOS, deprecated: 16.0)
@available(macOS, deprecated: 13.0)
@available(tvOS, deprecated: 16.0)
@available(watchOS, deprecated: 9.0)
private extension SwiftUI.Toggle where Label == SwiftUI.Text {
init<C>(_ titleKey: LocalizedStringKey, sources: C, isOn: KeyPath<C.Element, Binding<Bool>>) where C : RandomAccessCollection {
@krzyzanowskim
krzyzanowskim / box.swift
Created June 3, 2023 10:36
A SwiftUI wrapper around NSBox
/// A SwiftUI wrapper around `NSBox`.
public struct Box<Content>: View where Content: View {
private let title: String?
private let content: () -> Content
public init(_ title: String? = nil, @ViewBuilder content: @escaping () -> Content) {
self.title = title
self.content = content
}
@krzyzanowskim
krzyzanowskim / NSRange+NSTextContentManager.swift
Created February 15, 2022 18:03
NSRange TextKit2 helpers
extension NSRange {
static let notFound = NSRange(location: NSNotFound, length: 0)
var isEmpty: Bool {
length == 0
}
init(_ textRange: NSTextRange, in textContentManager: NSTextContentManager) {
let offset = textContentManager.offset(from: textContentManager.documentRange.location, to: textRange.location)
@krzyzanowskim
krzyzanowskim / FB9959997_NSResponder_undoManager.md
Last active May 4, 2023 10:10
NSResponder.undoManager is not used (FB9959997)

According to documentation it's enough to override NSResponder.undoManager to provide custom NSUndoManager instance. I found it's not quite working:

  • Xcode Mac application template comes with Undo menu item bind to firstResponder.undo: despite NSResponder has no undo: selector defined. Unless first responder actually respond to undo: the Undo action doesn't work
  • NSFirstResponder.undoManager look up in responder chain and eventually it end up in NSWindow where the only place (that I found) that validate Undo menu item is NSWindow.validateUserInterfaceItem - that one, as turned out, only ever validate undo: action if first responder implements _getUndoManager: selector (quite private, isn't it?) - see attached disassembly

at this point 🤕 I start to think it's either documentation issue, or AppKit implementation issue. Anyway, I didn't found way to enable undo: action unless I implement one of these methods in my NSView. (notice: the view is first responder tha

@krzyzanowskim
krzyzanowskim / blogpost.txt
Last active May 4, 2023 08:25
Designing a Stunning macOS Icon for Your Text Editor: A Step-by-Step Guide https://twitter.com/krzyzanowskim/status/1653742801014726658
Title: Designing a Stunning macOS Icon for Your Text Editor: A Step-by-Step Guide
Introduction:
In the world of macOS applications, an eye-catching icon plays a crucial role in attracting users and conveying the essence of your software. When it comes to a text editor, your macOS icon should reflect the simplicity, elegance, and functionality of your application. In this blog post, we will explore the art of designing a stunning macOS icon for your text editor, step by step. Let's dive in!
Step 1: Understand Your Brand and Target Audience:
Before starting the icon design process, it's important to have a clear understanding of your brand and target audience. Ask yourself questions like: What are the unique features of your text editor? What emotions or feelings do you want your icon to evoke? Understanding your brand and target audience will help you create an icon that resonates with your users.
Step 2: Research and Inspiration:
Take some time to research existing macOS icons, especially those in the text
@krzyzanowskim
krzyzanowskim / pitch.md
Last active March 17, 2023 18:13
Swift Studio Investment Pitch

Dear [Name] Investments,

I am excited to introduce Swift Studio, a cutting-edge platform for Swift development, specifically tailored to Swift on Server. As you know, Swift is quickly gaining popularity as a language for developing server-side applications, and Swift Studio is the perfect tool for developers looking to take advantage of this trend.

Swift Studio is a comprehensive development environment that streamlines the development process by providing an intuitive user interface and powerful features. With Swift Studio, developers can easily create, test, and deploy Swift applications for the server, all in one place.

One of the key features of Swift Studio is its real-time collaboration functionality, which allows multiple developers to work on the same project simultaneously. This feature enhances productivity and promotes teamwork, making Swift Studio an ideal solution for larger development teams.

Additionally, Swift Studio integrates seamlessly with other popular development tools and technologi

import Foundation
struct EmojiUnkeyedEncodingContainer : UnkeyedEncodingContainer {
// MARK: Properties
private(set) public var codingPath: [CodingKey]
private var encoder: EmojiEncoder;
/// The number of elements encoded into the container.
public var count: Int {
/// NavigationSplitView default a List in left view to Sidebar style, and then swipeActions modifier stop working. It's a multi level regression. The swipeActions has been broken for a while, but in macOS 12 it didn't work in .sidebar list style neither
NavigationSplitView {
List {
ForEach(list, id: \.self) { item in
HStack {
Text(item.title)
}
.contentShape(Rectangle())
}
// Marcin Krzyzanowski
// blog.krzyzanowskim.com
import Foundation
extension URLResourceKey {
static let bookmarkAllPropertiesKey = URLResourceKey("NSURLBookmarkAllPropertiesKey")
static let fileIDKey = URLResourceKey("_NSURLFileIDKey")
static let inode = URLResourceKey.fileIDKey
}
/// This code defines an init method for the Binding type. This method accepts three parameters:
///
/// An object of any type T
/// A key path to a property of type Value on that object
/// An optional UndoManager object
///
/// The init method sets the Binding value to the value of the property specified by the key path. It also sets the set value of the Binding to a closure that updates the value of the property at the key path and registers an undo operation with the provided UndoManager, if one is given.
///
/// This allows the Binding object to be used to access and update the value of the specified property on the provided object, and to register undo operations for those updates with the UndoManager.