Skip to content

Instantly share code, notes, and snippets.

@usagimaru
usagimaru / DumpAllMethods.swift
Last active March 28, 2024 19:52
Get all methods of an class or instance in Swift
// Dump all NSApplication’s class methods
let dump = NSApplication.perform(NSSelectorFromString("fp_methodDescription")).takeUnretainedValue() as? String
// Dump all NSApplication’s instance methods
let dump = NSApp.perform(NSSelectorFromString("fp_methodDescription")).takeUnretainedValue() as? String
// or
print(NSApplication.value(forKey: "fp_methodDescription"))
print(NSApp.value(forKey: "fp_methodDescription"))
@kkebo
kkebo / ContentView.swift
Last active October 24, 2023 15:13
SwiftUI のプレビュー上でユニットテストを実行する Proof of Concept (ContentView のテストをしたい場合)
import SwiftUI
struct ContentView: View {
@State var hoge = 0
@Environment(\.testCaseNumber) private var testCaseNumber
func change() {
hoge = 3
}
@pdarcey
pdarcey / SwiftData.md
Last active January 22, 2025 17:51
SwiftData storage on the Mac

SwiftData storage on the Mac

Where does SwiftData store things on the Mac?

Default Storage Location

On iOS, this directory is in the app's own storage location (app_UUID/Library/Application Support) but, on the Mac, it's a shared location in the user's Library.

By default on the Mac, SwiftData stores its model in the /~/Library/Application Support directory as default.store. (It will also add two other files, default.store-shm and default.store-wal, as the model is stored as a SQLite database, and these are these additional files are part of how SQLite works.)

@usagimaru
usagimaru / createdmg_shortcut.sh
Last active February 5, 2024 03:09
My `create-dmg` script for macOS
#!/bin/sh
in_dir_name=$1
the_app_name=$2
out_dmg_name=$3
bg_image=$4
## https://github.com/create-dmg/create-dmg
create-dmg \
@usagimaru
usagimaru / HowCalcMacMenuBarHeight.md
Last active December 16, 2023 03:39
macOSメニューバーの高さをバックグラウンドプロセスから正しく取得するには

macOSメニューバーの高さをバックグラウンドプロセスから正しく取得するには

バックグラウンドに常駐するアプリケーションでメニューバーの高さを計算する必要があった。いくつかの方法を試してみたが、冴えたやり方が存在しない模様。(13.x Ventura)

考慮事項

  • バックグラウンドプロセスからメニューバーの高さを正しく取得したい
  • メニューバーを隠す設定が有効な場合、それを考慮する
  • メニューバーの高さはそもそも固定値ではない
  • ノッチ無しMacでは、どの解像度でもメニューバーの高さは24pt固定(常時表示の場合/単位はpxではないことに注意)
@othyn
othyn / App.swift
Last active February 5, 2025 13:28
How to disable default menu bar items in Swift / SwiftUI for macOS
//
// App.swift
//
// Created by Ben Tindall on 30/03/2022.
//
import Foundation
import SwiftUI
import Cocoa
@takoikatakotako
takoikatakotako / ContentView.swift
Created January 6, 2022 05:00
iOS15でPickerを横に並べるとタップ領域が重なってしまう回避策
import SwiftUI
struct ContentView: View {
@State private var hour: Int = 8
@State private var minute: Int = 30
var body: some View {
VStack {
Text("Hour: \(hour), Minute: \(minute)")
TimePicker(hour: $hour, minute: $minute)