はじめに
デバッグを楽にするためにPrefixをカスタムします
実装
prefix operator ~~ // ここは記号のみ
extension String {
static prefix func ~~(_ str: String) -> String {
return "✅: \(str)"
}
}
使い方
import SwiftUI
struct ContentView: View {
var body: some View {
Button {
print(~~"テスト")
} label: {
Text("プリント")
}
}
}
出力
✅: テスト
おわり
prefix operator
なんて初めて知りました