Skip to content

Instantly share code, notes, and snippets.

View benigumocom's full-sized avatar
🏠
🙆

chanzmao benigumocom

🏠
🙆
View GitHub Profile
@benigumocom
benigumocom / showtable.swift
Last active February 13, 2024 01:55
【Swift】配列をコンソールにテーブル形式で表示する 👉 https://android.benigumo.com/20240213/show-table/
extension Array where Element: Collection, Element.Index == Int {
func showTable() {
transposed()
.map { $0.map { "\($0)" } }
.map {
let max = $0.map { $0.countAsHalfWidth }.max()!
return $0.map { $0.padding(length: max) }
}
.transposed()
.map { "| " + $0.joined(separator: " | ") + " |" }
@benigumocom
benigumocom / Pong.swift
Last active February 23, 2024 15:02
【 SwiftUI 】 Pong Wars を SwiftUI に移植してみた 👉 https://android.benigumo.com/20240201/pong-wars/
import Foundation
@Observable final class Pong {
var squares: [Square] = []
var balls: [Ball] = []
var dayCount = 0
var nightCount = 0
var generation = 0
private var cols = 0
@benigumocom
benigumocom / transpose-matrix.swift
Last active February 1, 2024 02:23
【Swift】2次元配列 で 転置行列 ( transpose matrix ) 👉 https://android.benigumo.com/20240201/transpose-matrix/
extension Collection where Element: Collection,
Self.Index == Int, Element.Index == Int {
func transposed1() -> [[Element.Element]] {
let cols = 0 ..< (self.first?.count ?? 0)
let rows = 0 ..< self.count
var result: [[Element.Element]] = []
for col in cols {
var newRow: [Element.Element] = []
for row in rows {
@benigumocom
benigumocom / versions.txt
Last active March 3, 2025 10:26
iOS Version Market Share
2025-03-03
+------+------------+-------+-------+----------+----------+
| iOS | RELEASE | WW % | JP % | WW SUM % | JP SUM % |
+======+============+=======+=======+==========+==========+
| 16.0 | 2022-09-12 | 0.59 | 0.61 | 91.15 | 93.86 |
+------+------------+-------+-------+----------+----------+
| 16.1 | 2022-10-24 | 1.23 | 1.43 | 90.56 | 93.25 |
+------+------------+-------+-------+----------+----------+
| 16.2 | 2022-12-13 | 0.62 | 0.79 | 89.33 | 91.82 |
+------+------------+-------+-------+----------+----------+
@benigumocom
benigumocom / BackyardBirdsDataContainer.swift
Last active January 22, 2024 01:15
【 #SwiftData 】ModelContainer の View へのセット 👉 https://android.benigumo.com/20240122/modelcontainer/
import SwiftUI
import SwiftData
struct BackyardBirdsDataContainerViewModifier: ViewModifier {
let container: ModelContainer
init(inMemory: Bool) {
container = try! ModelContainer(for: DataGeneration.schema, configurations: [ModelConfiguration(isStoredInMemoryOnly: inMemory)])
}
@benigumocom
benigumocom / BackyardBirdsDataContainer.swift
Last active January 22, 2024 01:15
【 #SwiftData 】ModelContainer の View へのセット 👉 https://android.benigumo.com/20240122/modelcontainer/
import SwiftUI
import SwiftData
public extension View {
func backyardBirdsDataContainer(inMemory: Bool = true) -> some View {
modifier(DataContainerViewModifier(inMemory: inMemory))
}
}
struct DataContainerViewModifier: ViewModifier {
import SwiftUI
// 1
//struct Parent: View {
// @State private var isOn = false
//
// var body: some View {
// VStack {
// Rectangle().fill(isOn ? .yellow : .gray)
// Toggle(isOn ? "ON" : "OFF", isOn: $isOn)
@benigumocom
benigumocom / adjust_layout.swift
Last active December 29, 2023 03:35
【#SwiftUI】レイアウトの調整に View.background(Color.*) が便利だな 👉 https://android.benigumo.com/?p=30338&preview=true
struct ItemRow: View {
var body: some View {
VStack(alignment: .leading) {
Text("ベイスターズ優勝")
.font(.headline)
.background(.white) // *
Text("2023-12-28")
.font(.caption)
.foregroundStyle(.secondary)
.background(.red) // *
@benigumocom
benigumocom / State-Binding.swift
Last active December 24, 2023 07:18
【SwiftUI】@State を 子 View でどう受けるか 🤔 - @binding 👉 https://android.benigumo.com/20231224/state-binding/
import SwiftUI
import PlaygroundSupport
struct ParentView: View {
@State private var text: String = ""
var body: some View {
VStack {
TextField("Parent", text: $text)
Text(text)
struct BirdsSearchResults<Content: View>: View {
private var searchText: Binding<String>
private var content: (Bird) -> Content
@Query(sort: \Bird.creationDate) private var birds: [Bird]
init(searchText: Binding<String>, @ViewBuilder content: @escaping (Bird) -> Content) {
self.searchText = searchText
self.content = content
}