Skip to content

Instantly share code, notes, and snippets.

View bannzai's full-sized avatar
スターください

bannzai bannzai

スターください
View GitHub Profile
@bannzai
bannzai / Tick.swift
Created August 15, 2024 17:36
Tick.swift
import Combine
import SwiftUI
class _Tick: ObservableObject {
@Published var now: Date = .now
let timer: Publishers.Autoconnect<Timer.TimerPublisher>
init(every: TimeInterval = 1) {
timer = Timer.publish(every: every, on: .main, in: .common)
.autoconnect()
@bannzai
bannzai / Document.swift
Created August 1, 2024 06:03
Document.swift
import Foundation
import FirebaseFirestore
import FirebaseFirestoreSwift
protocol SetIdentifiable: Identifiable {
mutating func set(id: ID)
}
typealias AnyEntity = Codable & Sendable & Hashable & Identifiable & SetIdentifiable
// onCall等でEntityを返す際にDocumentIDで以下のエラーになる。そのためonCallでのレスポンスはEntityを使用して、Firestoreからのデータ取得はDocument<Entity>を使用する
@bannzai
bannzai / add_sendable.sh
Last active September 3, 2024 14:12
struct, enumに無心でSendableをつけるsed。Viewは除外
#!/bin/bash
TARGET_DIR=$1
echo "やるお"
for file in $(find "$TARGET_DIR" -name "*.swift"); do
# struct User: * { の場合。ただし、View適応は除く
sed -i '' -E '/struct [A-Za-z0-9_]+: [^{]*View[^{]*\{/!s/(struct [A-Za-z0-9_]+: [^{]*)\{/\1, Sendable {/g' "$file"
sed -i '' -E '/enum [A-Za-z0-9_]+: [^{]*View[^{]*\{/!s/(enum [A-Za-z0-9_]+: [^{]*)\{/\1, Sendable {/g' "$file"
import SwiftUI
struct AsyncAction<Content: View>: View {
@State var isLoading = false
@State var task: @Sendable @MainActor () async -> Void
@ViewBuilder let content: (Bool, @escaping () -> Void) -> Content
var body: some View {
content(isLoading, {
if isLoading {
[
{
"word": "Asshole",
"kana": "アスホール",
"meaning": "いやな奴(Ass=お尻、Hole=穴)",
"notice": "「うざい野郎」「ろくでなし」"
},
{
"word": "あばずれ",
"kana": "あばずれ",
@bannzai
bannzai / CarouselView.swift
Last active October 21, 2024 08:34
CarouselView.swift
import SwiftUI
struct Item: Identifiable {
let id = UUID()
var text = ""
var color: Color = .clear
}
struct CarouselView: View {
var items: [Item] = [
@bannzai
bannzai / add_print_changes.sh
Last active September 20, 2024 21:41
Self._printChanges() を入れたり外したり
#!/bin/zsh
TARGET_DIR=$1
SCRIPT_DIR="$(cd `dirname $0` && pwd -P)"
REPOSITORY_ROOT_DIR="$(cd $SCRIPT_DIR && cd .. && pwd -P)"
find "$REPOSITORY_ROOT_DIR/$TARGET_DIR" -name "*.swift" -exec sed -i '' '/var body: some View {/a\
let _ = Self._printChanges()
' {} \;
@bannzai
bannzai / generate_translated_localizable_strings.py
Created October 6, 2023 09:50
generate_translated_localizable_strings.py
import json
import os
import openai
openai.organization = os.environ.get("OPENAI_ORGANIZATION")
openai.api_key = os.environ.get("OPENAI_API_KEY")
langs = ['fr']
@bannzai
bannzai / NavigationControllerApp.swift
Last active August 8, 2023 11:30
NavigationStack
class NavigationController: ObservableObject {
@Published var path: NavigationPath = .init()
var destinations: [UUID: () -> any View] = [:]
func push(id: UUID = .init(), @ViewBuilder destination: @escaping () -> some View) {
destinations[id] = destination
path.append(id)
}
func pop() {
path.removeLast()
import SwiftUI
import AVKit
struct ContentView: View {
@State var soundLabelIsShows = false
var body: some View {
ZStack(alignment: .center) {
Image("kane")
.resizable()