Question

I am trying to write data to a file and then read it out again. It looks like I have the correct structure to write it but nothing shows up when I read it. Can someone please take a look and see if I am missing something. Here is the code snippet

 NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

//LOADING TITLE ONTO DEVICE///////
NSString *title =[NSString stringWithFormat:@"%@_title.txt",[[prodlist objectAtIndex:indexPath.row] objectForKey:@"appSKU"]];
DLog(@"Title = %@",title);
NSString *titlePath = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",title]]; //add our title to the path
DLog(@"Path = %@",titlePath);
if(![[NSFileManager defaultManager] fileExistsAtPath:titlePath]) {
    DLog(@"Content = %@",product.localizedTitle);
    [product.localizedTitle writeToFile:descripPath atomically:NO];

}
//////////////////////////////////
//cell.AppTitle.text = product.localizedTitle;
    DLog(@"Path1 = %@",titlePath);
    DLog(@"Content1 = %@",[NSString stringWithContentsOfFile:titlePath encoding:NSUTF8StringEncoding error:nil]);
cell.AppTitle.text = [NSString stringWithContentsOfFile:titlePath encoding:NSUTF8StringEncoding error:nil];

My Log file indicates to me at least that I have the correct path In these two attempts though nothing seem to be returning

2013-06-02 09:15:15.698 IMOB[35034:907] <MasterViewController.m:(144)> Title = app_0101_title.txt
2013-06-02 09:15:15.699 IMOB[35034:907] <MasterViewController.m:(146)> Path = /var/mobile/Applications/1C1ACE22-25ED-47A8-98D0-50AFA0C4415E/Documents/app_0101_title.txt
2013-06-02 09:15:15.700 IMOB[35034:907] <MasterViewController.m:(148)> Content = Relax Sleep Well Full
2013-06-02 09:15:15.707 IMOB[35034:907] <MasterViewController.m:(161)> Path1 = /var/mobile/Applications/1C1ACE22-25ED-47A8-98D0-50AFA0C4415E/Documents/app_0101_title.txt
2013-06-02 09:15:15.709 IMOB[35034:907] <MasterViewController.m:(162)> Content1 = (null)
2013-06-02 09:15:15.725 IMOB[35034:907] <MasterViewController.m:(144)> Title = app_0102_title.txt
2013-06-02 09:15:15.726 IMOB[35034:907] <MasterViewController.m:(146)> Path = /var/mobile/Applications/1C1ACE22-25ED-47A8-98D0-50AFA0C4415E/Documents/app_0102_title.txt
2013-06-02 09:15:15.728 IMOB[35034:907] <MasterViewController.m:(148)> Content = Lose Weight Now
2013-06-02 09:15:15.735 IMOB[35034:907] <MasterViewController.m:(161)> Path1 = /var/mobile/Applications/1C1ACE22-25ED-47A8-98D0-50AFA0C4415E/Documents/app_0102_title.txt
2013-06-02 09:15:15.738 IMOB[35034:907] <MasterViewController.m:(162)> Content1 = (null)
Was it helpful?

Solution

I think your writeToFile method is referring to a variable descripPath which should be titlePath?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top