admin管理员组文章数量:1794759
Object
犀利吐槽
1.同样都是“文件和目录操作",java中,就用java.util.File一个类,就封装了很多API,而Object-C搞了这么多类和函数。具体原因,有待分析啊。
2.明明是NSString,字符串操作,怎么出现了”pathComponents“等操作文件路径相关的方法,很奇怪的赶脚。
3.stringByAppendingString,这函数的名字有点长啊。
4.总体感觉,Object-C的语法比Java复杂一些,码代码的效率低了不少。
/
// main.m
// FilePathUtil
//
// Created by fansunion on 15/11/29.
// Copyright (c) 2015年 demo. All rights reserved.
//#import <Foundation/Foundation.h>//演示文件路径API
int main(int argc, const char * argv[]) {@autoreleasepool {NSString *fileName =@"path.m";NSFileManager *fm;NSString *path,*tempDir,*extention,*homeDir,*fullPath;NSArray *components;fm =[NSFileManager defaultManager];//临时目录tempDir = NSTemporaryDirectory();NSLog(@"The tempDir is %@",tempDir);//提取基本目录path =[fm currentDirectoryPath];NSLog(@"The base dir is %@",[path lastPathComponent]);//fileName在当前目录中的完整路径//这个地方有个问题//本地输出”/Users/fansunion/Library/Developer/Xcode/DerivedData/FilePathUtil-bvzjqehotbexooebruphtwcmqekz/Build/Products/Debugpath.m“//Debug和path.m之间没有”分隔符“/",而书本中的例子是有的//最好还是手动加上,Java中也是没有这个分隔符,需要手动加上的fullPath =[path stringByAppendingString:fileName];NSLog(@"The fullPath is %@",fullPath);//获得文件扩展名extention = [fullPath pathExtension];NSLog(@"The extentions is %@",extention);//获得用户的主目录homeDir = NSHomeDirectory();NSLog(@"The home directory is %@",homeDir);//拆分路径为各个组成部分components = [homeDir pathComponents];for(path in components){NSLog(@"%@",path);}}return 0;
}
程序输出
2015-11-29 13:43:30.550 FilePathUtil[2861:179163] The tempDir is /var/folders/4q/5ylpds9n5n97bq_r41qvly4w0000gn/T/
2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The base dir is Debug
2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The fullPath is /Users/fansunion/Library/Developer/Xcode/DerivedData/FilePathUtil-bvzjqehotbexooebruphtwcmqekz/Build/Products/Debugpath.m
2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The extentions is m
2015-11-29 13:43:30.552 FilePathUtil[2861:179163] The home directory is /Users/fansunion
2015-11-29 13:43:30.552 FilePathUtil[2861:179163] /
2015-11-29 13:43:30.552 FilePathUtil[2861:179163] Users
2015-11-29 13:43:30.553 FilePathUtil[2861:179163] fansunion
Program ended with exit code: 0
本文标签: object
版权声明:本文标题:Object 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1692778556a189802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论