Skip to content

Instantly share code, notes, and snippets.

View kkebo's full-sized avatar
📱
Using iPad Pro 12.9” (6th gen.)

Kenta Kubo kkebo

📱
Using iPad Pro 12.9” (6th gen.)
View GitHub Profile
@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
}
@kkebo
kkebo / ContentView.swift
Last active May 1, 2023 14:09
`ContentView` reads child files recursively when you drag and drop a directory.
struct ContentView: View {
@State private var isTargeted = false
var body: some View {
Rectangle()
.fill(self.isTargeted ? .green : .white)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onDrop(of: [.directory], isTargeted: self.$isTargeted) { providers in
for provider in providers {
_ = provider.loadFileRepresentation(for: .directory, openInPlace: true) { url, _, _ in
@kkebo
kkebo / main.js
Last active November 13, 2022 10:36
@wasmer/wasi@0.10.2 で swift-format.wasm のリリースビルドバイナリが実行できない再現コード
const fs = require('fs-extra')
const { WASI } = require('@wasmer/wasi')
const wasiBindings = require('@wasmer/wasi/lib/bindings/node')
const { lowerI64Imports } = require("@wasmer/wasm-transformer")
const wasi = new WASI({
args: ['swift-format', '--version'],
env: {},
bindings: wasiBindings.default,
preopens: {'.': '.'}
@kkebo
kkebo / crash.swift
Last active October 12, 2022 16:45
Xcode Previews 上でプレビューのプロセスがクラッシュするコード (実機だと問題なし) (macOS 12.3 & Xcode 13.3 や iPadOS 15.4 & Swift Playgrounds 4.0.2 で再現することを確認) (Swift 5.7 で修正)
import SwiftUI
// 再現する型: URL, URLError, UUID, Date, Measurement, Locale, some SwiftUI.View
// 再現しない型: String, [Int], [String: Int], some StringProtocol, DispatchQueue, Bundle, Data, DateFormatter, URLSession, JSONEncoder, NSNumber, CGFloat, Decimal, SwiftUI.Text
func foo() async -> URL {
.init(fileURLWithPath: "/")
}
struct ContentView: View {
@kkebo
kkebo / ssh.plist
Last active September 25, 2022 11:16
Plist file for LaunchAgents when OpenSSH is installed via Homebrew (for macOS 13 aarch64)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<true/>
<key>Label</key>
<string>com.openssh.sshd.homebrew</string>
<key>Program</key>
<string>/opt/homebrew/sbin/sshd</string>
@kkebo
kkebo / arm64-apple-ios.swiftinterface.swift
Created May 22, 2022 10:32
PackgeDescription in Swift Playgrounds 4.1
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
// swift-module-flags: -target arm64-apple-ios14.7 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -package-description-version 999.0 -module-name PackageDescription
// swift-module-flags-ignorable: -user-module-version 15
import Foundation
import Swift
public struct BuildConfiguration : Swift.Encodable {
public static let debug: PackageDescription.BuildConfiguration
public static let release: PackageDescription.BuildConfiguration
public func encode(to encoder: Swift.Encoder) throws
@kkebo
kkebo / arm64-apple-ios-macabi.swiftinterface.swift
Last active May 22, 2022 10:31
AppleProductTypes in Swift Playgrounds 4.1
// From /Applications/Playgrounds.app/Contents/Toolchain/usr/lib/swift/pm/ManifestAPI/AppleProductTypes.swiftmodule/arm64-apple-ios-macabi.swiftinterface
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
// swift-module-flags: -target arm64-apple-ios13.4-macabi -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -package-description-version 999.0 -module-link-name AppleProductTypes -module-name AppleProductTypes
// swift-module-flags-ignorable: -user-module-version 15
import PackageDescription
import Swift
extension PackageDescription.Product {
@kkebo
kkebo / ExportIPA.swift
Last active November 13, 2023 09:23 — forked from rileytestut/ExportIPA.swift
Export Swift Playgrounds .ipa
import class Foundation.Bundle
import class Foundation.FileManager
import class Foundation.NSFileAccessIntent
import class Foundation.NSFileCoordinator
import class Foundation.NSMutableDictionary
import struct Foundation.URL
import struct Foundation.UUID
import var Foundation.kCFBundleIdentifierKey
import var Foundation.kCFBundleNameKey
@kkebo
kkebo / ContentView.swift
Created September 13, 2021 15:42
iOS の Light/Dark mode 選択の設定みたいな Picker
import PlaygroundSupport
import SwiftUI
struct ContentView: View {
@State var selection = 0
var body: some View {
HStack {
Button {
self.selection = 0
@kkebo
kkebo / Box.swift
Last active July 30, 2021 21:08
Rust の Box 的なやつを Swift で (Box はヒープに置くことが目的、BoxObject は参照にすることが目的)
@propertyWrapper
public struct Box<Value> {
private var object: BoxObject<Value>
public var value: Value {
get { self.object.value }
set {
if !isKnownUniquelyReferenced(&self.object) {
self.object = self.object.copy()
}