4
3

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】URLの部分抽出

Posted at

URLの構造

ダウンロード.png

こちらのサイトで詳しく説明されています。

プロトコルの抽出

import Foundation

var url = URL(string: "https://taishin-miyamoto.com/ShadowBan?screen_name=SNQ2001")

print(url?.scheme ?? "")

// https

ドメインの抽出

import Foundation

var url = URL(string: "https://taishin-miyamoto.com/ShadowBan?screen_name=SNQ2001")

print(url?.host ?? "")

// taishin-miyamoto.com

ディレクトリの抽出

import Foundation

var url = URL(string: "https://taishin-miyamoto.com/ShadowBan?screen_name=SNQ2001")

print(url?.path ?? "")

// /ShadowBan

クエリパラメータの抽出

import Foundation

var url = URL(string: "https://taishin-miyamoto.com/ShadowBan?screen_name=SNQ2001")

print(url?.query ?? "")

// screen_name=SNQ2001

おわり

以前URLのスキームで振り分けようと思ったことがありまして、
その際に調べてもあまり情報がなかったので備忘録として記事にしました。
誰かの役に立てば嬉しいです。

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?