NSURL

NSURL 中的各种属性代表的意义

NSURL *url = [NSURL URLWithString:@"http://www.baidu.com/search?id=1"];
NSLog(@"scheme:%@",[url scheme]);//scheme:http
NSLog(@"host:%@",[url host]);//host:www.baidu.com
url = [NSURL URLWithString:@"http://www.baidu.com:8080/search?id=1"];
NSLog(@"port:%@",[url port]);//port:8080
url = [NSURL URLWithString:@"http://www.baidu.com:8008/search#identifier=1&user=101010"];
NSLog(@"fragment:%@",[url fragment]);//fragment:identifier=1&user=101010
url = [NSURL URLWithString:@"http://www.baidu.com:8008/search?identifier=1&user=101010"];
NSLog(@"query:%@",[url query]);//query:identifier=1&user=101010
NSLog(@"absoluteString:%@",[url absoluteString]);//absoluteString:http://www.baidu.com:8008/search?identifier=1&user=101010
url = [NSURL URLWithString:@"http://www.baidu.com:8008/search/find/second?identifier=1&user=101010"];
NSLog(@"path:%@",[url path]);//path:/search/find/second
NSLog(@"relativePath:%@",[url relativePath]);//relativePath:/search/find/second
NSLog(@"pathComponents:%@",[url pathComponents]);//pathComponents:(
                                                        "/",
                                                        search,
                                                       find,
                                                       second
                                                 )

你可能感兴趣的:(NSURL)