0

假设您有一个看起来像的 URL,http://localhost:5867并且您想将“/something”附加到该 URL。如何将段附加到此 URL?我正在尝试这个:

//_baseURL is NSURL* and documentid is NSString*
NSURL* url = [_baseURL URLByAppendingPathComponent:documentid];

奇怪的是.. xcode(4.6.2) 不会将生成的 URL 输出到控制台。

 NSLog(@"%@", [url absoluteString]);//nothing output

谢谢!

编辑

我在工作区工作。我正在调试的代码是工作区中的静态库。这可能是所有这些怪异的罪魁祸首吗?

固定的

我认为我遇到问题的原因是因为我的工作区配置不正确,而我实际上正在执行旧版本的静态库。这解释了为什么我没有得到 NSLog'ing 以及为什么结果出乎意料。我发现这篇文章帮助我了解了工作区以及如何为静态库配置它。非常感谢大家的时间!

4

2 回答 2

1

有上课留言,

+ (id)URLWithString:(NSString *)URLString relativeToURL:(NSURL *)baseURL

所以,

NSURL *base  = [NSURL URLWithString: @"http://localhost:5867"];
NSURL *child = [NSURL URLWithString: @"something" relativeToURL:base];
于 2013-06-11T02:03:01.990 回答
0
NSURL *base  = [NSURL URLWithString:@"http://localhost:5867"];
NSURL *url = [base URLByAppendingPathComponent:@"something"];

NSLog(@"%@", [url absoluteString]);

这适用于我和打印http://localhost:5867/something,所以检查你的变量(也许其中一个是nil或一个空字符串?)。

于 2013-06-11T02:07:15.423 回答