【发布时间】:2014-01-02 00:05:58
【问题描述】:
在将字符串解析为 NSURL 对象时,NSURL 将使用单个正斜杠的字符串与在方案后使用双正斜杠的字符串区别对待。
为什么会这样?
这里有一些例子:
NSURL *url = [NSURL URLWithString:@"app-id://path1/path2"];
NSLog(@"%@",url.scheme); // "app-id"
NSLog(@"%@",url.path); // "/path2"
NSLog(@"%@",url.host); // "path1"
NSURL *url = [NSURL URLWithString:@"app-id:/path1/path2"];
NSLog(@"%@",url.scheme); // "app-id"
NSLog(@"%@",url.path); // "/path1/path2"
NSLog(@"%@",url.host); // nil
【问题讨论】:
-
有趣的是,
://之前的任何内容都被视为方案,即您可以编写“giberish://path1/path2”然后乱码将是您的方案。通常是http。
标签: ios cocoa nsurl core-foundation nsurlcomponents