stringByAppendingPathComponent中的基础错误?
问题描述:
我尝试以下线的iOS应用程序,并在基础工具:stringByAppendingPathComponent中的基础错误?
[@"http://www.apple.com/" stringByAppendingPathComponent:@"/"]
每次的结果我得到的是:
@"http:/www.apple.com"
换句话说,stringByAppendingPathComponent
,除了不追加任何东西(我预期的),吞下最后的/
(可以认为是OK,排序),和咽下一个URL模式/
,这完全是不是确定在我的书中。
这是只发生在我身上吗?在提交错误报告之前,我错过了一些愚蠢的事情吗?
答
首先,请注意文档stringByAppendingPathComponent:
:
注意,此方法只与文件路径(不,例如,字符串的URL的表示)的作品。
因此,您正在使用该方法,它并不意味着支持。
与文件路径使用它显示了相同的行为,但:
[@"/abc/" stringByAppendingPathComponent:@"/"]; // -> @"/abc"
[@"/abc/" stringByAppendingPathComponent:@"/def/"]; // -> @"/abc/def"
所以这种方法似乎总是喜欢那些不以斜杠,不管最终是否斜杠是部分路径原始路径或参数。不过,我不知道我是否会说这个错误。毕竟,/abc
和/abc/
在文件系统上指定了相同的项目,不是吗?
但它确实听起来像确切的行为可以更好地记录。
arf,我没有看到文档中的注释。好吧不是一个错误。我的错。谢谢。 – 2011-04-06 15:27:09
这也失败了:'[[NSURL URLWithString:@“http://www.apple.com”] URLByAppendingPathComponent:@“/”]'。它返回'http://www.apple.com ///'。 'URLWithString:relativeToURL:'似乎工作正常,但。 – 2011-04-06 15:43:07