title: Parsing a .csv file from a server with Objective-C
body: <p>I have looked for an answer of a long time and still not found one so I thought I'd ask the question myself.</p>
  
  <p>In my iPad app, I need to have the capability of parsing a .csv file in order to populate a table. I am using <a href="http://michael.stapelberg.de/cCSVParse" rel="nofollow">http://michael.stapelberg.de/cCSVParse</a> to parse the csv files. However, I have only been successful in parsing local files.  I have been trying to access a file from a server but am getting nowhere. </p>
  
  <p>Here is my code to parse a local .csv file:</p>
  
  <pre><code>- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  {
      if (buttonIndex == 1)
      {
          //UITextField *reply = [alertView textFieldAtIndex:buttonIndex];
          NSString *fileName = input.text;
          NSLog(@"fileName %@", fileName);
          CSVParser *parser = [CSVParser new];
          if ([fileName length] != 0)
          {
              NSString *pathAsString = [[NSBundle mainBundle]pathForResource:fileName ofType:@"csv"];
              NSLog(@"%@", pathAsString);
  
              if (pathAsString != nil)
              {
                  [parser openFile:pathAsString];
                  NSMutableArray *csvContent = [parser parseFile];
                  NSLog(@"%@", csvContent);
                  [parser closeFile];
                  NSMutableArray *heading = [csvContent objectAtIndex:0];
                  [csvContent removeObjectAtIndex:0];
  
                  NSLog(@"%@", heading);
  
                  AppDelegate *ap = [AppDelegate sharedAppDelegate];
                  NSManagedObjectContext *context = [ap managedObjectContext];
  
                  NSString *currentHeader = [heading objectAtIndex:0];
                  NSString *currentValueInfo = [heading objectAtIndex:1];
                  NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:@"Field" inManagedObjectContext:context];
                  [newObject setValue:@"MIS" forKey:@"header"];
                  [newObject setValue:currentHeader forKey:@"fieldName"];
  
                  for (NSArray *current in csvContent)
                  {
                      NSManagedObject *newField = [NSEntityDescription insertNewObjectForEntityForName:@"Field" inManagedObjectContext:context];
                      [newField setValue:currentHeader forKey:@"header"];
                      [newField setValue:currentValueInfo forKey:@"valueInfo"];
                      NSLog(@"%@", [current objectAtIndex:0]);
                      [newField setValue:[current objectAtIndex:0] forKey:@"fieldName"];
                      [newField setValue:[NSNumber numberWithDouble:[[current objectAtIndex:1] doubleValue]] forKey:@"value"];
                  }
                  NSError *error;
                  if (![context save:&amp;error]) 
                  {
                      NSLog(@"Couldn't save: %@", [error localizedDescription]);
                  }
                  [self storeArray];
                  [self.tableView reloadData];
              }
          }
      }
      input.text = nil;
  }
  </code></pre>
  
  <p>Forgive the weird beginning and ending brace indentation. :/</p>
  
  <p>Anyway, so that is my code to take input from a user and access a file locally which I'm sure you guys have realized already.  Now I want to know how to get the path of a file in my server. </p>
  
  <p>Also if you guys see anything else wrong such as writing style and other bad habits please tell me as I'm new to iOS. </p>
  
  <p>Thank you so much in advance! If you didn't understand my question please clarify as I'm bad at explaining myself at times! :)</p>