Objective-C获取用户完整路径
我正在用XCode学习Objective-C 我想要得到用户的完整路径目录,我得到了“良好”的返回,但是没有用户的完整路径(/User/Asinox),我只得到了NSPathStore2 我尝试使用NSHomeDirectoryForUser()和StringByExpandingTildeInPath,结果是一样的(NSPathStore2) 在MAC OS X 10.6.4上使用XCode 3.2.3和SDK 4.0.1进行即时通讯Objective-C获取用户完整路径,objective-c,cocoa,Objective C,Cocoa,我正在用XCode学习Objective-C 我想要得到用户的完整路径目录,我得到了“良好”的返回,但是没有用户的完整路径(/User/Asinox),我只得到了NSPathStore2 我尝试使用NSHomeDirectoryForUser()和StringByExpandingTildeInPath,结果是一样的(NSPathStore2) 在MAC OS X 10.6.4上使用XCode 3.2.3和SDK 4.0.1进行即时通讯 #import <Foundation/Founda
#import <Foundation/Foundation.h>
void PrintPathInfo(){
//NSString *path = @"~";
NSString *directory = NSHomeDirectoryForUser(@"asinox");//[path stringByExpandingTildeInPath];
NSArray *pathComponents = [directory pathComponents];
NSLog(@"My home folder is at %@", *directory);
NSLog(@"===============================");
for(NSString *ruta in pathComponents){
NSLog(@"%@", ruta);
}
NSLog(@"===============================");
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
PrintPathInfo();
[pool release];
return 0;
}
#导入
void PrintPathInfo(){
//NSString*路径=@“~”;
NSString*directory=nshomeditoryforuser(@“asinox”);/[path stringByExpandingTildeInPath];
NSArray*pathComponents=[directory pathComponents];
NSLog(@“我的主文件夹位于%@”,*目录);
NSLog(@“=================================================”);
用于(路径组件中的NSString*ruta){
NSLog(@“%@”,ruta);
}
NSLog(@“=================================================”);
}
int main(int argc,const char*argv[]{
NSAutoreleasePool*池=[[NSAutoreleasePool alloc]init];
PrintPathInfo();
[池释放];
返回0;
}
是一个类群集
由于类集群的性质,字符串对象不是NSString或NSMutableString类的实际实例,而是它们的一个私有子类的实例
NSPathStore2
是一个私有的NSString
子类,它可能专用于处理路径,因此,与非优化的替代方法相比,可以更快地执行与路径相关的方法,例如stringByAppendingPathComponent:
或pathExtension
您得到的输出是什么?是一个类集群
NSLog(@"My home folder is at %@", *directory);
由于类集群的性质,字符串对象不是NSString或NSMutableString类的实际实例,而是它们的一个私有子类的实例
NSPathStore2
是一个私有的NSString
子类,它可能专用于处理路径,因此,与非优化的替代方法相比,可以更快地执行与路径相关的方法,例如stringByAppendingPathComponent:
或pathExtension
您得到的输出是什么
NSLog(@"My home folder is at %@", *directory);
应该是
NSLog(@"My home folder is at %@", directory);
应该是
NSLog(@"My home folder is at %@", directory);