2009-11-23 61 views

回答

1

您可以使用下面的代碼(從my answer吸引到this question),以確定你的數據庫的大小和文件系統的空閒空間都:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *persistentStorePath = [documentsDirectory stringByAppendingPathComponent:@"database.sqlite"]; 

NSError *error = nil; 
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:persistentStorePath error:&error]; 
NSLog(@"Persistent store size: %@ bytes", [fileAttributes objectForKey:NSFileSize]); 

NSDictionary *fileSystemAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:persistentStorePath error:&error]; 
NSLog(@"Free space on file system: %@ bytes", [fileSystemAttributes objectForKey:NSFileSystemFreeSize]); 

這假定您的數據庫被稱爲「database.sqlite」並存儲在應用程序文檔目錄的根目錄中。

0

您可以找到database文件,在iPhone模擬器中的應用,在

~/Library/Application Support/iPhone Simulator/User/Applications/*a long number*/Documents/ 

如果你有監獄打破手機,您可以SSH成它並找到應用程序文件夾,它也將位於/Applications/*<a long number>*/Documents/文件夾中。

1

嘗試以下,這可以幫助你

- (NSString *)applicationDocumentsDirectory { 
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; 
} 

- (void) logSqlliteStoreSize 
{ 
    NSString *yourSqlLiteFileName = @"YOURDATABASE_NAME.sqlite"; 
    NSString *yourSqlLitePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: yourSqlLiteFileName]; 
    NSError *error; 
    NSDictionary *storeAttributesOfItemAtPath = [[NSFileManager defaultManager] attributesOfItemAtPath:yourSqlLitePath error:&error]; 
    // here you should test for errors, this is a simplified version 

    // the next log will show much information about your sqlite file 
    // including the filesize 
    NSLog(@"storeAttributesOfItemAtPath=%@", storeAttributesOfItemAtPath); 

} 
相關問題