0
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】最もシンプルな HTTP/S レスポンスボディ取得 (非同期処理含む)

Last updated at Posted at 2024-05-26

「for」にこんな実力があるとは !

let url = URL(string: "https://wttr.in/?format=3")!
for try await line in url.lines {
  print(line)
}

// Kisarazu, Japan: ⛅️  +25°C

と思っていたら、String にもこんな力が!

print(
  try! String(contentsOf: URL(string: "https://wttr.in/?format=3")!)
)

// Kisarazu, Japan: ⛅️  +25°C

😅 つまらないので追記

sc 2024-05-26 at 21.20.48.gif

ボディ は プレーンなテキストなので連続上書き後の最終行だけ。

非同期必須の cancel や exception は無視。

🧑🏻‍💻 参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?