Skip to content

Instantly share code, notes, and snippets.

View YusukeHosonuma's full-sized avatar
🏠
Working from home

Yusuke Hosonuma YusukeHosonuma

🏠
Working from home
View GitHub Profile
import SwiftUI
struct EnumPicker<Enum>: View where Enum: CaseIterable & Hashable, Enum.AllCases: RandomAccessCollection {
typealias Element = Enum.AllCases.Element
private var enumType: Enum.Type
@Binding private var selection: Element
init(_ enumType: Enum.Type, selection: Binding<Element>) {
self.enumType = enumType
@YusukeHosonuma
YusukeHosonuma / ContentView.swift
Created August 29, 2023 04:41
SwiftUI: 某エディタの透明度アイコン的な
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
OpacityIcons(content: OpacityIcon1.init)
OpacityIcons(content: OpacityIcon2.init)
}
.padding()
}
@YusukeHosonuma
YusukeHosonuma / ContentView.swift
Created August 1, 2023 01:44
SwiftUI: The Laughing Man(笑い男)のロゴ
import SwiftUI
import Algorithms
struct ContentView: View {
@State var angle: Double = 0
var body: some View {
TimelineView(.animation()) { time in
Waraiotoko(angle: angle)
.onChange(of: time.date) { _, _ in
@YusukeHosonuma
YusukeHosonuma / goodbye_swiftgen_localize.rb
Created May 23, 2023 01:30
Goodbye Localizable.strings with SwiftGen - SwiftGen によるローカライズを剥がすスクリプト
# -----------------------------------------------------------------------------
# SwiftGen によるローカライズを剥がすスクリプト。
# -----------------------------------------------------------------------------
class String
# シンボル変換
def symbol
# e.g.
# - OK → Ok
# - FAQ → Faq
@YusukeHosonuma
YusukeHosonuma / golden_apple.js
Created January 5, 2023 15:12
🍎 Appleドキュメントからコードをコピペした時に余計な空行が入らないようにする
// ==UserScript==
// @name Golden Apple
// @namespace http://tampermonkey.net/
// @version 0.1
// @description When source code is copied and pasted from Apple documentation, unnecessary line breaks should no longer be inserted.
// @author @tobi462
// @match https://developer.apple.com/documentation/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// ==/UserScript==
@YusukeHosonuma
YusukeHosonuma / PureList.swift
Last active June 22, 2023 02:42
[SwiftUI] PureList
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
PureList {
Text("Apple")
.border(.red)
Color.clear
@YusukeHosonuma
YusukeHosonuma / ContentView.swift
Last active December 12, 2022 16:49
After: [SwiftUI] タブがタップされた時に上までスクロールする。あるいはそれを共通化する話。
import SwiftUI
struct ContentView: View {
@State private var selectedTab: Tab = .first
var body: some View {
TabContainer(selection: $selectedTab) { tabTappedTwices in
ForEach(Tab.allCases) { tab in
SampleView(
title: tab.title,
@YusukeHosonuma
YusukeHosonuma / ContentView.swift
Last active December 12, 2022 16:49
Before: [SwiftUI] タブがタップされた時に上までスクロールする。あるいはそれを共通化する話。
extension Binding {
func willSet(_ handler: @escaping (Value) -> ()) -> Binding<Value> {
.init(
get: { wrappedValue },
set: { newValue in
handler(newValue)
wrappedValue = newValue
}
)
}
@YusukeHosonuma
YusukeHosonuma / ForEachIndex.swift
Created December 4, 2022 03:31
ForEachIndex (with Algorithms)
import SwiftUI
import Algorithms
struct ForEachIndex<Data: RandomAccessCollection, ID: Hashable, Content: View>: View {
typealias Element = IndexedCollection<Data>.Element
private var data: Data
private var id: KeyPath<Element, ID>
@ViewBuilder private var content: (Element) -> Content
@YusukeHosonuma
YusukeHosonuma / ContentView.swift
Created December 3, 2022 04:56
SwiftUI: minXxx / maxXxx / fixedSize
struct ContentView: View {
var body: some View {
VStack(spacing: 50) {
// minWidth / minHeight
Color.blue.opacity(0.3)
.frame(minWidth: 100, minHeight: 200)
.frame(width: 150, height: 150)
.border(.black)
.overlay {