1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Swift】文字列内の"(ダブルクォーテーション)をエスケープするのがめんどくさい

Posted at

はじめに

SwiftでJSONを文字列で定義しようとするとこんな感じになります

スクリーンショット 2023-09-11 21.51.53.png

これを解決するためにバックスラッシュでエスケープします

スクリーンショット 2023-09-11 21.51.37.png

ただ、これがめんどう!!

これをしなくていい方法があります

やりかた

#で囲むだけでOK!

let text = #"{"name": "Taishin", "age": 22}"#

スクリーンショット 2023-09-11 21.52.14.png

おわり

めっちゃ簡単ですね

1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?