我有一个简单而又相当前瞻的方法。 它应该创建一个文件夹,如果它不存在。 它需要一个正确声明的字符串参数。参数未在方法中收到
当我使用它并传递一个参数时,接收变量保持为空,这很奇怪,因为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'应该有一个类型? – 2012-02-19 04:05:28