Skip to content

Instantly share code, notes, and snippets.

View nukka123's full-sized avatar

nukka123 nukka123

View GitHub Profile
@nukka123
nukka123 / DefaultStringInterpolation-opt-or.swift
Created May 2, 2025 15:46
DefaultStringInterpolation "\(opt:or)"
extension DefaultStringInterpolation {
mutating func appendInterpolation<T>(
opt value: T?,
or alternative: @autoclosure () -> String = String(describing: Optional<T>.none)
) {
if let value {
appendInterpolation(value)
} else {
appendLiteral(alternative())
@nukka123
nukka123 / swiftui-binding-bool.swift
Created May 2, 2025 15:17
swiftui-binding-bool
extension Binding {
func bool<T>() -> Binding<Bool> where Value == Optional<T> {
Binding<Bool> (
get: {
self.wrappedValue != nil
},
set: { newValue in
// alertはボタンタップで非表示に変化の時にfalseをsetする。
// その際には、元のOptional値をnilに更新する。
if !newValue {
@nukka123
nukka123 / main.swift
Last active August 30, 2019 13:35
Swift String Basics
import Foundation
let s1 = "(Hello, String, か゚か゚か゚)"
print("s1:", s1)
let c1: Character = "A"
let c2: Character = "B"
let s2 = String([c1, c2])
print("s2:", s2)