Skip to content

Instantly share code, notes, and snippets.

View takoikatakotako's full-sized avatar

Kabigon Ono takoikatakotako

View GitHub Profile
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:27
SwiftUIでアラートのメッセージを出し分ける
import SwiftUI
struct ContentView: View {
@State var alertMessage: String = ""
@State var showingAlert: Bool = false
var body: some View {
HStack(spacing: 20) {
Button {
alertMessage = "This is Ditto!!!"
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:25
SwiftUIでローカル通知を送信する
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Button {
requestAuthorization()
} label: {
Text("Request Authorization")
.font(Font.system(size: 24).bold())
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:23
Swiftで10進数を2進数に変換する
import SwiftUI
struct ContentView: View {
@State var numberString = ""
@State var result = ""
var body: some View {
VStack {
Text("Decimal Number -> Binary Number")
TextField("Input Number", text: $numberString)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:22
SwiftUIでAppDelegateを使用する
import SwiftUI
struct ContentView: View {
@State var pokemon = ""
var body: some View {
VStack {
Text("Pokemon Name is \(pokemon)")
Button {
UserDefaults().setValue("Pikachu", forKey: "POKEMON")
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:18
SwiftUIでグラフを表示する
import SwiftUI
import Charts
struct ContentView: View {
var body: some View {
ScrollView {
VStack {
// Vertical Graph
Chart {
BarMark(
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:12
SwiftUIでdelegateを使用する
import SwiftUI
struct ContentView: View, MyProtocol {
@State var text: String = "My Text"
var body: some View {
NavigationView {
VStack {
Text(text)
NavigationLink(destination: SecondView(delegate: self)) {
Text("2nd View")
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:09
SwiftUIで音楽を再生する
import SwiftUI
import AVFoundation
struct ContentView: View {
@State var player: AVAudioPlayer?
var body: some View {
VStack {
Button {
let url = Bundle.main.url(forResource: "drum", withExtension: "mp3")!
do {
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:05
SwiftUIでテーブルのようなデータを表示する
import SwiftUI
struct ContentView: View {
let pokemonData = [
Column(
title: "No",
rows: ["143", "1", "7", "50", "143", "1", "7", "50", "143", "1", "7", "50", "143", "1", "7", "50", "143", "1", "7", "50", "143", "1", "7", "50"]
),
Column(
title: "Name",
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:04
NavigationStackのpathを使って画面遷移する
import SwiftUI
struct ContentView: View {
@State var path: [ViewPath] = []
var body: some View {
NavigationStack(path: $path) {
VStack {
Text("ContentView")
.font(.title)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 13:01
SwiftUIでBadgeを表示する
import SwiftUI
struct ContentView: View {
@State var message = ""
@State var showingAlert = false
var body: some View{
VStack {
Button {
Task {
do {