Skip to content

Instantly share code, notes, and snippets.

@eonil
eonil / HPSFNavigationStack.swift
Last active December 20, 2023 22:14
HPSFNavigationStack
import SwiftUI
import UIKit
struct HPSFNavigationStack<SliceID: Hashable, Content: View>: View {
private var spec: Spec
enum Action {
case userNavigation([SliceID])
}
init(slices: [SliceID], content: @escaping (SliceID) -> Content) {
spec = Spec(slices: slices, content: content, action: noop)
@eonil
eonil / README.md
Created June 11, 2022 16:15 — forked from IsaacXen/README.md
(Almost) Every WWDC videos download links for aria2c.
@eonil
eonil / gist:1aa12ecacf1a4b2566fe
Last active October 31, 2021 12:35
Cocoa Note

Cocoa Note (including AppKit)

  • NSLayoutManager.setTemporaryAttributes(:forCharacterRange:) is far faster than NSTextStorage.setAttributes(:range:). On My iMac, former took about 2 seconds, and latter took about 17 seconds in optimised build of test suit.

  • Anyway, modifying NSTextStorage also took 2 seconds when wrapped by beginEditing/endEditing pair. So this performance drop is mainly due to inefficient layout refresh. You will get same performance

@eonil
eonil / ci.bash
Created September 10, 2020 11:52
How to build iOS app project without signing with simulator test.
cd TestApp1
DEST="platform=iOS Simulator,name=iPhone 8,OS=13.6"
SIGNFLAGS="CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO"
xcodebuild clean build test -scheme TestApp1 -sdk iphonesimulator -destination "$DEST" $SIGNFLAGS
~
~
~
@eonil
eonil / impl.md
Last active July 7, 2020 03:01
An Opinion about How to Implement UI Apps for Apple Frameworks

An Opinion about How to Implement UI Apps for Apple Frameworks

Eonil, 2020.

This explains how I organize code of interactive programs.

Overview

@eonil
eonil / sample.swift
Created May 20, 2020 18:48
How to write imperative I/O control program with GCD (spawned thread) and Combine.
import Foundation
import Combine
final class Task<I,O> {
let control = PassthroughSubject<Int,Error>()
let report = PassthroughSubject<Int,Error>()
init() {
let i = Channel(control)
let o = Channel(report)
DispatchQueue.global().async { [i,o] in

UIKit Note

Autolayout

  • If you want self-sizing view by its subviews, just do not set its sizing constraint. Then it will become the
@eonil
eonil / sssl.swift
Created January 9, 2020 10:27
Single Selection SwiftUI List
//
// ContentView.swift
// SwiftUIWithNSWindowWithoutTitlebar1
//
// Created by Henry Hathaway on 1/9/20.
// Copyright © 2020 Eonil. All rights reserved.
//
import SwiftUI
@eonil
eonil / topologicalSort.swift
Last active December 27, 2019 18:34
Topological Sort in Swift
extension RelPath: Comparable {
/// Sorts by lexicographical topological order.
public static func < (_ a:RelPath, _ b:RelPath) -> Bool {
let c = Swift.min(a.count, b.count)
for i in 0..<c {
if a[i] < b[i] { return true }
if a[i] > b[i] { return false }
}
return a.count < b.count
}