0%

Objective-C 环境变量的读取

#import 

int main (int argc, const char * argv[])
{
    
    @autoreleasepool {
        NSFileManager *fm=[NSFileManager defaultManager];
        NSString *tempdir=NSTemporaryDirectory();
        
        NSLog(@"临时目录:%@",tempdir);
        
        NSString * currentPath=[fm currentDirectoryPath];
        NSLog(@"当前路径:%@",currentPath);
        
        NSString * filePath=[currentPath stringByAppendingPathComponent:@"main.m"];
        NSLog(@"当前文件路径:%@",filePath);
        
        NSString * extension=[filePath pathExtension];
        NSLog(@"当前文件扩展名:%@",extension);
        
        NSString * homeDir=NSHomeDirectory();
        NSLog(@"当前用户主目录:%@",homeDir);
        
        NSArray * components=[homeDir pathComponents];
        //用户主目录路径结构拆分
        for (NSString *path in components) {
            NSLog(@"%@",path);
        }
        
    }
    return 0;
    
}