[英]IOS - How do I add segments to NSURL?
假设您有一个看起来像http://localhost:5867
的URL,并且想要在该URL http://localhost:5867
附加“ / something”。 如何将细分附加到此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以及为什么结果出乎意料。 我发现这篇文章有助于我了解工作区以及如何为静态库配置它。 非常感谢大家的时间!
有一个班级消息,
+ (id)URLWithString:(NSString *)URLString relativeToURL:(NSURL *)baseURL
所以,
NSURL *base = [NSURL URLWithString: @"http://localhost:5867"];
NSURL *child = [NSURL URLWithString: @"something" relativeToURL:base];
NSURL *base = [NSURL URLWithString:@"http://localhost:5867"];
NSURL *url = [base URLByAppendingPathComponent:@"something"];
NSLog(@"%@", [url absoluteString]);
这对我http://localhost:5867/something
,并显示http://localhost:5867/something
,所以检查您的变量(也许其中之一是nil
还是空字符串?)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.