美文网首页iOSselector
NSURL 的几个属性 absoluteString

NSURL 的几个属性 absoluteString

作者: 原野de呼唤 | 来源:发表于2016-07-13 21:09 被阅读1024次

通过比较来了解一下NSURL的这几个属性.

NSURL *url = [NSURL URLWithString:@“ http://www.baidu.com/search?id=1 ”];

分别打印以下属性可以很好的理解它们的区别(NSLog后面的注释就是 %@ 的打印结果):

NSLog(@"scheme:%@", [url scheme]); //协议 http

NSLog(@"host:%@", [url host]);    //域名 www.baidu.com

NSLog(@"absoluteString:%@", [url absoluteString]); //完整的url字符串 http://www.baidu.com:8080/search?id=1

NSLog(@"relativePath: %@", [url relativePath]); //相对路径 search

NSLog(@"port :%@", [url port]);  // 端口 8080

NSLog(@"path: %@", [url path]);  // 路径 search

NSLog(@"pathComponents:%@", [url pathComponents]); // search

NSLog(@"Query:%@", [url query]);  //参数 id=1

相关文章

网友评论

    本文标题:NSURL 的几个属性 absoluteString

    本文链接:https://www.haomeiwen.com/subject/ydcejttx.html