Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:21:25+00:00 2026-06-17T19:21:25+00:00

This is more a open question than an error-related question, so if you don’t

  • 0

This is more a open question than an error-related question, so if you don’t like to answer these kinds of questions, please don’t flame.

I have a huge (!) list of ships in a .csv file, separated by ,

The matrix is organised like this:
enter image description here
repeated with different data about 500 times.

Now, I want this to be read into objects, which can be used further to populate a UITableView
Currently, I hard-code data into the object files, like this

arrayWithObjectsForTableView = [[NSMutableArray alloc] init];
if ([boatsFromOwner isEqualToString:@"Owner1"]) {
    cargoShips* ship = [[cargoShips alloc]init];
    ship.name = @"name1";
    ship.size = 1000;
    ship.owner = @"Owner1";

    [self.boatsForOwner addObject:ship];

    ship = [[cargoShips alloc]init];
    ship.name = @"Name 2";
    ship.size = 2000;
    ship.owner = @"Owner2";

And so on and on with if-else’s. This is a bad method, as
1) Its boring and takes a long time
2) It takes even more time if I want to update the information.
So, I figured it would be smarter to read programmatically from the matrix instead of doing it myself. Yeah, captain obvious came for a visit to my brain.

So, to the question!
How can I read the .csv file that looks like this:
enter image description here
add the ships of, say, owner, to a NSMutableArray, in the shape of objects. (So they can be used to feed my UITableView with ships.

I would also like to have the option to sort by different stuff, like Country of build, Operator etc. How can I make code that feeds relevant ships read from the .csv into objects?
I don’t know much programming, so in-depth answers would be very appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:21:26+00:00Added an answer on June 17, 2026 at 7:21 pm

    The depth of your processing will determine what sort of data structure is required for this task. This is the method I would use:

    1: Read the .csv file into one giant NSString object:

    NSString *file = [[NSString alloc] initWithContentsOfFile:yourCSVHere];
    

    2: Get the individual lines:

    NSArray *allLines = [file componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
    

    3: For each line, get the individual components:

    for (NSString* line in allLines) {
        NSArray *elements = [line componentsSeparatedByString:@","];
        // Elements now contains all the data from 1 csv line
        // Use data from line (see step 4)
    }
    

    4: This is where it’s up to you. My first thought would be to create a class to store all your data. For example:

    @interface Record : NSObject
    //...
    @property (nonatomic, copy) NSString *name
    @property (nonatomic, copy) NSString *owner
    // ... etc
    @end
    

    4a: Then, back in step 3 create a Record object for each line and then put all the Record objects into a separate NSArray (something with larger scope!).

    5: Use your NSArray that contains all your Record objects as the data source for your UITableView.

    The implementation of Steps 4 and 5 are up to you. That’s probably how I would do it though for a medium sized .csv file.

    EDIT: Here’s how to generate the Records.

    //
    NSMutableArray *someArrayWithLargerScope = [[NSMutableArray alloc] init];
    //
    
    NSString *file = [[NSString alloc] initWithContentsOfFile:yourCSVHere];
    NSArray *allLines = [file componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet];
    
    for (NSString* line in allLines) {
        NSArray *elements = [line componentsSeparatedByString@","];
        Record *rec = [[Record alloc] init];
        rec.name = [elements objectAtIndex:0];
        rec.owner = [elements objectAtIndex:1];
        // And so on for each value in the line.
        // Note your indexes (0, 1, ...) will be determined by the
        // order of the values in the .csv file.
        // ...
        // You'll need one `Record` property for each value.
    
        // Store the result somewhere
        [someArrayWithLargerScope addObject:rec];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of an open question rather than looking for one specific answer.
I know this question might be a bit more open ended than usually asked
Edit: Maybe I made the question more complex than it should. My questions is
This is more than likely a very simple question. I have an external javascript
I think this question is more of a coding style rather than technical issue.
This may sound like an odd question, but when I go and open a
EDIT: This question is more about language engineering than C++ itself. I used C++
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history
Ok, I'm going to try to make this more clear because my last question
I have a label on my asp.net page, it looks like this: more info

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.