Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 当一个URL为/Users/john格式,另一个为file://localhost/Users/etc_Objective C_Cocoa_Macos - Fatal编程技术网

Objective c 当一个URL为/Users/john格式,另一个为file://localhost/Users/etc

Objective c 当一个URL为/Users/john格式,另一个为file://localhost/Users/etc,objective-c,cocoa,macos,Objective C,Cocoa,Macos,我正在枚举返回URL格式的目录: file://localhost/Users/john/Documents/static.gif 我想以以下形式对照URL检查这些结果: /Users/john 具体来说,我想知道第一个URL是否包含在第二个URL中 我一直在研究各种NSURL方法,但找不到一种方法可以将一种形式转换为另一种形式以便于比较,或者实际为我进行比较。您可以使用路径方法获取字符串。第一个URL将变成@”/localhost/Users/john/Documents/static.g

我正在枚举返回URL格式的目录:

file://localhost/Users/john/Documents/static.gif
我想以以下形式对照URL检查这些结果:

/Users/john
具体来说,我想知道第一个URL是否包含在第二个URL中


我一直在研究各种NSURL方法,但找不到一种方法可以将一种形式转换为另一种形式以便于比较,或者实际为我进行比较。

您可以使用
路径
方法获取字符串。第一个URL将变成
@”/localhost/Users/john/Documents/static.gif“
,第二个保持不变

您可以使用

if ( [[URL1 path] hasPrefix:[URL2 path]] ) {
    NSLog(@"Contained");
}