【发布时间】:2012-03-09 22:22:42
【问题描述】:
我有一个简单且非常前卫的方法。 如果它不存在,它应该创建一个文件夹。 它需要一个正确声明的字符串参数。
当我使用它并传递一个参数时,接收变量保持为空,这很奇怪,因为 pathTo_Folder 是一个路径。
你知道为什么会这样吗?
//Declaration in .h
- (void) createFolder : (NSString *) thePath ;
//The call
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *homePath = [@"~" stringByExpandingTildeInPath];
NSString *pathTo_Folder = [NSString stringWithFormat:@"%@/Library/Application Support/prolog/",homePath];
[self createFolder : pathTo_Folder];
}
//In .m
- (void) createFolder: thePath {
BOOL isDir;
NSFileManager *fileManager = [NSFileManager defaultManager] ;
[fileManager fileExistsAtPath:thePath isDirectory: &isDir] ;
NSLog(@"Folder '%@' exists: %d",thePath,isDir) ;
if (isDir == FALSE)
{
[fileManager createDirectoryAtPath: thePath withIntermediateDirectories:YES attributes:nil error:nil];
}
}
【问题讨论】:
-
你不觉得
thePath应该有一个类型吗?
标签: objective-c methods parameters