0
1

More than 1 year has passed since last update.

【Swift】カスタムのPrefixOperatorを作成する

Posted at

はじめに

デバッグを楽にするために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なんて初めて知りました

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1