У меня есть приложение, которое включает пути, которые необходимо добавить в NSMutableArray, и writeToFile.
int r = arc4random() % 100;
int s = arc4random() % 100;
int e = arc4random() % 100;
NSLog(@"%i%i%i.MOV", r, s, e);
NSString * tempFileName = [NSString stringWithFormat:@"%i%i%i.MOV", r, s, e];
NSString * tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSString * documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * storePath = [documentsDirectory stringByAppendingPathComponent:tempFileName];
NSError *error = nil;
[[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:tempFilePath]
toURL:[NSURL fileURLWithPath:storePath]
error:&error];
if (error) {
NSLog(@"%@", error);
}
NSLog(@"Old File path : %@", tempFilePath);
NSLog(@"New File path : %@", storePath);
dayCounter ++;
videoDayCounter = [[NSMutableArray alloc] initWithContentsOfFile:dayCounterPath];
NSLog(@"DayCounter INIT");
[videoDayCounter addObject:dayCounter];
[videoDayCounter writeToFile:dayCounterPath atomically:YES];
NSLog(@"dayCounter wrote to file"); '
allVideos = [[NSMutableArray alloc] initWithContentsOfFile:allVideosPath];
NSLog(@"AllVideosINIT");
[allVideos addObject:storePath];
NSLog(@"array: %@", allVideos);
[allVideos writeToFile:allVideosPath atomically:YES];
[videoCount setText:[allVideos count]];
[daysLabel setText:[videoDayCounter count]];
[self dismissModalViewControllerAnimated:YES];
[picker release];
NSLog для allVideos возвращает NULL.
Я пытался создатьallVideosPath при запуске приложения
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *allVideosPath = [documentsDirectory stringByAppendingPathComponent:@"allVideos.plist"];
NSString *dayCounterPath = [documentsDirectory stringByAppendingPathComponent:@"dayCount.plist"];
BOOL booleanAllVideos;
BOOL booleanDayCounter;
NSFileManager *fileManager = [NSFileManager defaultManager];
booleanAllVideos = [fileManager fileExistsAtPath:allVideosPath];
booleanDayCounter= [fileManager fileExistsAtPath:dayCounterPath];
if(booleanAllVideos == NO)
{
NSMutableArray *allVideos = [[NSMutableArray alloc] initWithCapacity:3];
[allVideos writeToFile:allVideosPath atomically:YES];
}
if(booleanDayCounter == NO)
{
NSMutableArray *videoDayCounter = [[NSMutableArray alloc] initWithCapacity:3];
[allVideos writeToFile:dayCounterPath atomically:YES];
}
Но я думаю, это не сработает?
Спасибо!