file://localhost/directory/といったURL文字列にstringByAppendingPathComponent:を使うと・・・

やっちゃ駄目って書いてあるからやるほうが悪いんですが・・


stringByAppendingPathComponent:のリファレンスには下記のように書いてあります。

Note that this method only works with file paths (not, for example, string representations of URLs).

file pathsでだけ動くと書いてありますが、表題のようにfile://localhost/....となっている文字列で実行してみると・・・

NSString *baseURLString = @"file://localhost/directory/";
NSString *fullPath = [baseURLString stringByAppendingPathComponent:@"index.html"];
NSLog(@"%@",fullPath);
// file:/localhost/directory/index.html

file:/localhost/... というように、file:の後の//が/に削られてしまいます。
stringByAppendingPathComponent:は使用せず、stringByAppendingString:を使うとか、

NSString *baseURLString = @"file://localhost/directory/";
NSString *fullPath = [baseURLString stringByAppendingString:@"index.html"];
NSLog(@"%@",fullPath);
// file://localhost/directory/index.html

ただ、stringByAppendingString:を使った場合だと、当然ながらpathを考慮されているわけではないです。
例えばpathComponentsを格納した配列から取り出して、個別に連結するといった場合には"/"を自前処理する必要があります。
文字列に%20であるとかが含まれれば、stringByReplacingPercentEscapesUsingEncoding:も必要です。

NSURLのインスタンスにして処理したほうがいいでしょう。

NSString *baseURLString = @"file://localhost/directory/";
NSURL *baseURL = [NSURL URLWithString:baseURLString];
NSString *fullPath = [[baseURL URLByAppendingPathComponent:@"index.html"] absoluteString];
NSLog(@"%@",fullPath);
// file://localhost/directory/index.html