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 7674455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:44:27+00:00 2026-05-31T16:44:27+00:00

I have a @property listOfSites declared in a class. I am unable to access

  • 0

I have a @property listOfSites declared in a class. I am unable to access listOfSites from another class, even tho’ I have done an #import of that class’ .h file. All I did was change an instance of the listOfSites to a property.

This is the code from another class (slTableViewController) where I send message to get listOfSites:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if([[segue identifier] isEqualToString:@"viewSitesSegue"])  {
        NSLog(@"viewSitesSegue");

        //  get list of sites
        slSQLite *dbCode = [[slSQLite alloc] init];
        [dbCode getListOfSites];

        //  put site data into array for display
        slSQLite *item = [[slSQLite alloc] init];
        NSLog(@"\n2-The array listOfSites contains %d items", item.listOfSites.count);

Here is the code for listOfSites:

-  (void) getListOfSites {

    FMDatabase *fmdb = [FMDatabase databaseWithPath:databasePath];  // instantiate d/b
    if(![fmdb open])  {
        NSLog(@"\nFailed to open database");
        return;
    }

    NSMutableArray *listOfSites = [[NSMutableArray alloc] init];

    FMResultSet *rs = [fmdb executeQuery: @"SELECT SITE_ID, SITE_DESC, DATE FROM SiteData WHERE SITE_ID <> '0'"];
    while([rs next])  {
        sArray *sa = [[sArray alloc] init];
        sa.sSiteID = [rs stringForColumnIndex:0];
        sa.sJobDesc = [rs stringForColumnIndex:1];
        sa.sJobDate = [rs stringForColumnIndex:2];

        [listOfSites addObject:sa];  //  add class object to array
    }

    NSLog(@"\nThe array listOfSites contains %d items", listOfSites.count);

    [fmdb close];
}
  • 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-31T16:44:28+00:00Added an answer on May 31, 2026 at 4:44 pm

    To be able to access listOfSites from other classes, you need to make it a property of that class:

    In the MyClass.h file

    @interface MyClass : NSObject
    
    // ...
    
    @property (strong, nonatomic) NSMutableArray *listOfSites;
    
    // ...
    
    @end
    

    Then you have to synthesize in the MyClass.m file

    @interface MyClass
    
    @synthesize listOfSites;
    
    // ...
    
    @end
    

    Now, if you import MyClass.h in another class, then you can access the property listOfSites. For example in another file OtherClass.m:

    #import "MyClass.h"
    
    // ...
    
    - (void)someMethod {
        MyClass *item = [[MyClass alloc] init];
        item.listOfSites = [[NSMutableArray alloc] init];
        // ...
    }
    

    You are making many mistakes in the posted code. (Even assuming you correctly declared listOfSites as a property).

    First, change the line:

    NSMutableArray *listOfSites = [[NSMutableArray alloc] init];
    

    into:

    listOfSites = [[NSMutableArray alloc] init];
    

    Second, in the following lines:

    slSQLite *dbCode = [[slSQLite alloc] init]; // Create an object
    [dbCode getListOfSites]; // Generate the content of listOfSites
    
    //  put site data into array for display
    slSQLite *item = [[slSQLite alloc] init]; // Create another object
    NSLog(@"\n2-The array listOfSites contains %d items", item.listOfSites.count); // Log the length of listOfSites in this new object
    

    you are generating the content of listOfSites for the object dbCode, and checking the length of listOfSites in item which is a different object and for which you didn’t generate the content of listOfSites.

    Try the following instead:

    slSQLite *dbCode = [[slSQLite alloc] init]; // Create an object
    [dbCode getListOfSites]; // Generate the content of listOfSites
    NSLog(@"\n2-The array listOfSites contains %d items", dbCode.listOfSites.count); // Log the length of listOfSites in dbCode
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a property on a domain object that is declared in a many-to-one
I have a property within a class, that I need to iterate through all
I have a property on a class that happens to be a Table<T> .
Say I have a tableview class that lists 100 Foo objects. It has: @property
I am trying to access and change a array from a different class file.
I have a View class (extends ViewPart ) that contains a ScrolledForm created from
I have a property called IsSecureConnection that is part of my object's interface. This
I have a property of type uint on my entity. Something like: public class
I have property definition in class where i have only Counters, this must be
Say I have: @property (nonatomic,retain) NSString *foo; in some class. And I call: myclass.foo

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.