打电话时,+[NSURL URLWithString:]
我有两个选项来构建我的 URL:
[[@"http://example.com" stringByAppendingPathComponent:@"foo"] stringByAppendingPathComponent:@"bar"]
或者
[@"http://example.com" stringByAppendingFormat:@"/%@/%@",@"foo",@"bar"];
-[NSString stringByAppendingPathComponent:]
似乎是更正确的答案,但是-[NSString stringByAppendingFormat:]
除了在以下情况下处理双斜杠之外,我还会丢失任何东西吗?
// http://example.com/foo/bar
[[@"http://example.com/" stringByAppendingPathComponent:@"/foo"] stringByAppendingPathComponent:@"bar"]
// http://example.com//foo/bar oops!
[@"http://example.com/" stringByAppendingFormat:@"/%@/%@",@"foo",@"bar"];