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

  • Home
  • SEARCH
  • 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 5946741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:51:55+00:00 2026-05-22T16:51:55+00:00

I’m creating a SQLite application, with two simple views. I have two arrays in

  • 0

I’m creating a SQLite application, with two simple views. I have two arrays in SQLAppDelegate:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    self.modelArray = tempArray;
    self.detailArray = tempArray;
    [tempArray release];

So now in my implementation file I am populating “modelArray” with the contents of a SQLite table and displaying this in the first view:

+ (void) getInitialDataToDisplay:(NSString *)dbPath {

    SQLAppDelegate *appDelegate = (SQLAppDelegate *)[[UIApplication sharedApplication] delegate];

    if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

        const char *sql = "select rowid as ID, ManufacturerMake as modelName from sqlitedb group by modelName";
        sqlite3_stmt *selectstmt;
        if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

            while(sqlite3_step(selectstmt) == SQLITE_ROW) {

                NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
                Model *modelObj = [[Model alloc] initWithPrimaryKey:primaryKey];
                modelObj.modelName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];


                [appDelegate.modelArray addObject:modelObj];
                [modelObj release];
            }

        }
    }

The problem is that modelArray is being populated correctly with 114 rows, but if I do a count of detailArray after the above while statement this is also returning 114? Even though I’m not touching detailArray in the above code?

  • 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-05-22T16:51:56+00:00Added an answer on May 22, 2026 at 4:51 pm
    self.modelArray = tempArray;
    self.detailArray = tempArray;
    

    Here both your instance variable arrays contain pointer to the same NSMutableArray instance (assuming that your property has retain attribute), so changes to the one of the iVars are also applied to another one (as they point to the same object).

    To fix that initialize your arrays with different NSMutableArray’s:

    - (void)applicationDidFinishLaunching:(UIApplication *)application {
        self.modelArray = [NSMutableArray array];
        self.detailArray = [NSMutableArray array];
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.