Skip to content

Instantly share code, notes, and snippets.

View benigumocom's full-sized avatar
🏠
🙆

chanzmao benigumocom

🏠
🙆
View GitHub Profile
@benigumocom
benigumocom / GitHub-Contribution-Graph.swift
Last active April 2, 2024 03:15
【SwiftUI】 スクレイピングで GitHub Contribution Graph をつくる 👉 https://android.benigumo.com/20240402/github-contributions/
import SwiftUI
struct Graph: View {
@State var cells: [Cell] = []
private let colors: [Color] = [.clear, .level0, .level1, .level2, .level3, .level4]
var body: some View {
Grid(horizontalSpacing: 2, verticalSpacing: 2) {
ForEach(0 ..< 7, id: \.self) { row in
@benigumocom
benigumocom / TestTaskID.swift
Last active March 26, 2024 13:38
【SwiftUI】task の id を使って処理を何度も繰り返す 👉 https://android.benigumo.com/20240326/task-id/
import SwiftUI
struct TestTaskID: View {
@State private var text = ""
@State private var taskID = UUID()
var body: some View {
Text("\(text)")
.task(id: taskID) { // *
let url = URL(string: "https://worldtimeapi.org/api/timezone/Asia/Tokyo.txt")!
import SwiftUI
struct TestView: View {
@State var id = false
var body: some View {
AutoProgressView()
.padding()
.id(id)
import Foundation
import SwiftUI
import AVFoundation
struct SystemSoundWheelPicker: View {
@State private var sounds: [SystemSoundID] = []
@State private var playingID = -1
var body: some View {
Picker("", selection: $playingID) {
@benigumocom
benigumocom / serialize-async-functions.swift
Last active March 6, 2024 02:35
【Swift】非同期関数の直列実行 - withCheckedContinuation 👉 https://android.benigumo.com/20240305/sereial-async/
import SwiftUI
import AVFoundation
struct TestView: View {
var body: some View {
Button("Play1") {
AudioServicesPlaySystemSound(1000)
}
Divider()
@benigumocom
benigumocom / SystemSoundGrid.swift
Last active March 9, 2024 08:39
【Swift】SystemSoundID 一覧がないのですが 👉 https://android.benigumo.com/20240304/system-sound-id/
@Observable final class Sound: Identifiable {
var id: SystemSoundID
var duration: Double
var playing: Bool
var valid: Bool { self.duration > 0.01 }
init(_ id: Int, _ duration: Double, _ playing: Bool) {
self.id = SystemSoundID(id)
self.duration = duration
import SwiftUI
@Observable final class ScheduledTimer {
var elapsed = TimeInterval.zero
private var timer: Timer?
func start() {
timer = Timer.scheduledTimer(withTimeInterval: 0.001, repeats: true) { _ in
self.elapsed += 0.001
}
@benigumocom
benigumocom / CustomViewModifier.swift
Last active February 21, 2024 09:16
【SwiftUI】カスタム ViewModifier の使い方と使いどころ 🤔 👉 https://android.benigumo.com/20240221/custom-viewmodifier/
import SwiftUI
struct TestView: View {
var body: some View {
VStack {
Text("top")
Text("bottom")
}
import Foundation
// inspiered by
// lifegame/swift/lifegame.swift at master · tex2e/lifegame
// https://github.com/tex2e/lifegame/blob/master/swift/lifegame.swift
@Observable final class LifeGame {
var field: [[Int]] = []
var generation = 0
@benigumocom
benigumocom / convert_and_chunk_array.swift
Last active February 11, 2024 14:34
Convert 1D array to 2D array and vice versa, chunk array by n pieces each 👉 https://android.benigumo.com/20240211/handle-array/
let d2: [[String]] = [
// x (col) →
["あ", "い", "う", "え", "お"],
["か", "き", "く", "け", "こ"],
["さ", "し", "す", "せ", "そ"]
]
print(d2)
// [["あ", "い", "う", "え", "お"], ["か", "き", "く", "け", "こ"], ["さ", "し", "す", "せ", "そ"]]