1
2

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】DataをStringに変換する

Posted at

はじめに

URLSessionなどで通信した場合、結果はData型で返ってきます。
しかし、Data型では中身がどうなっているかわからないので文字列に変換して、中身を確認する必要があります。
その際に頻繁に使うので記録しておきます。

やりかた

let dataString = String(data: data, encoding: .utf8)

おわり

私はSwiftを勉強する前は、Pythonをやっていました。
Pythonではjsonを扱うのがめっちゃ簡単でデコード用の構造体など用意する必要がなかったので、初心者の時はSwiftめんど!って思ってました笑

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?