阅读 202

NSURL的scheme, path和query等各接口输出结果

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSURL *url = [NSURL URLWithString:@"http://www.testurl.com:8080/subpath/subsubpath?uid=123&gid=456"];
    
    NSLog(@"scheme = %@",[url scheme]);//    http
    
    NSLog(@"host = %@",[url host]);//    www.testurl.com
    
    NSLog(@"port = %@",[url port]);//    8080
    
    NSLog(@"path = %@",[url path]);//    /subpath/subsubpath
    
    NSLog(@"lastPathComponent = %@",[url lastPathComponent]);//    subsubpath
    
    NSLog(@"query = %@",[url query]);//    uid=123&gid=456
    
    NSLog(@"absoluteString = %@", [url absoluteString]);//http://www.testurl.com:8080/subpath/subsubpath?uid=123&gid=45
    
    //相对路径 search
    NSLog(@"relativePath = %@", [url relativePath]);//           /subpath/subsubpath
}

@end
复制代码
文章分类
iOS
文章标签