[iOS] Get the domain part of an URL string?

Objective-C

NSString* urlString = @"http://someurl.com/something";
NSURL* url = [NSURL URLWithString:urlString];
NSString* domain = [url host];

Swift 2

var urlString = "http://someurl.com/something"
var url = NSURL(string: urlString)
var domain = url?.host

Swift 3+

var urlString = "http://someurl.com/something"
var url = URL(string: urlString)
var domain = url?.host

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *