+ (void)findAndCopyOfDatabaseIfNeeded{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [path objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"DB"];
BOOL success = [fileManager fileExistsAtPath:databasePath];
if(!success){
NSString *resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"DB"];
[fileManager copyItemAtPath:resourcePath toPath:databasePath error:NULL];
}
NSString *tracePath = [documentsDirectory stringByAppendingPathComponent:@"Trace"];
BOOL traceDir = [fileManager fileExistsAtPath:tracePath];
if(!traceDir){
NSString *resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Trace"];
[fileManager copyItemAtPath:resourcePath toPath:tracePath error:NULL];
}
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy"];
NSDate *today = [[NSDate alloc]init];
NSString *resultYear = [dateFormatter stringFromDate:today];
NSString *traceYearPath = [tracePath stringByAppendingPathComponent:resultYear];
BOOL yearDir = [fileManager fileExistsAtPath:tracePath];
if (!yearDir) {
[fileManager createDirectoryAtPath:traceYearPath attributes:nil];
}
//[resultYear release]; ?
//[today release]; ?
//[dateFormatter release]; ?
}
I'm using global class like this [ + (void)findAndCopyOfDatabaseIfNeeded ]. hm,, I don't know NSArray, NSString and NSFileManager are released.
Variable release or Not release ? please advice for me.