ios开发之--NSURL的用法

NSURL *url = [NSURL URLWithString:@"http://www.baidu.com/search?id=1"];
    NSLog(@"scheme:%@",[url scheme]);//协议http
    NSLog(@"host:%@",[url host]);//域名www.baidu.com
    NSLog(@"absolutestring:%@",[url absoluteString]);//完整的url字符串
    NSLog(@"relativepath:%@",[url relativePath]);//相对路径 search
    NSLog(@"port:%@",[url port]);//端口
    NSLog(@"path:%@",[url path]);//路径
    NSLog(@"pthcomponents:%@",[url pathComponents]);//search
    NSLog(@"query:%@",[url query]);//参数

打印如下:

仅做记录!

原文地址:https://www.cnblogs.com/hero11223/p/9610880.html