And*_*son 2 iphone xcode cocoa-touch
我确信有更好的方法可以做到这一点.我有一大堆代码用于消灭iPhone或模拟器上的DocumentsDirectory.有时我只想要一个干净的平板,有时我会对数据库进行更改,我需要重建它.
因此,在我打开我的应用程序时调用的一个函数中,我已将此代码注释掉,并在我想要重置时删除注释块.你是做什么?
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *dirContents = [fileManager directoryContentsAtPath:[paths objectAtIndex:0]];
for (int i=0; i<[dirContents count]; ++i) {
NSString* theDir = [[paths objectAtIndex:0] stringByAppendingString:[@"/" stringByAppendingString:[dirContents objectAtIndex:i]]];
NSLog(theDir);
if ([fileManager removeItemAtPath: theDir error:NULL]) {
NSLog(@"removed dir");
}
}
Run Code Online (Sandbox Code Playgroud)
我是新手iPhone开发者.如果这就像Python服务器,我只会运行一个脚本,但我不确定XCode/iPhone的约定是什么.