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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:58:56+00:00 2026-06-07T12:58:56+00:00

I want to created and populate an Array in a class and then use

  • 0

I want to created and populate an Array in a class and then use the content in the array in the main program… As an example I’ll use a list of names of the US States…

This is an update on the original question that is halfway resolved and has been contented for clarity so you can see the code properly.

ArrayStates.h

#import <Foundation/Foundation.h>
@interface ArrayStates : NSObject
@end

ArrayStates.m

#import "ArrayStates.h"
@interface ArrayStates() { NSMutableArray *listOfStates; }
@implementation ArrayStates
- (void)viewDidLoad {
    //---initialize the array---
    listOfStates = [[NSMutableArray alloc] init];
    //---add items---
    [listOfStates addObject:@"ALABAMA"];

    [listOfStates addObject:@"WYOMING"];
    [super viewDidLoad];
}
@end

This is updated code from the previous Question but it still generates a Missing end error on the implementation line, the void wants a . after method prototype and you still can’t reference the object in the main program.

I believe altering the ordering if the interface and implementation differentiates whether the array can be accessed within or outside the class (thanks to iHungry for that).

  • 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-07T12:58:58+00:00Added an answer on June 7, 2026 at 12:58 pm
    // in ArrayStates.h
    @interface ArrayStates : NSObject
    @property NSMutableArray *listOfStates;
    @end
    
    // in ArrayStates.m
    @implementation ArrayStates
    @synthesize listOfStates;
    //...
    -(void)viewDidLoad {
        [super viewDidLoad];
        listOfStates = [[NSMutableArray alloc] init];
    }
    @end
    
    // in some other class
    ArrayStates *states = [[ArrayStates alloc] init];
    NSLog(@"%@", states.listOfStates);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this simple example, i want to create a String array populated with each
I've created a list of music file names in an array which is used
Is it possible to use javascript to populate multidimensional arrays. I want to create
I'm importing pre-created Crystal Reports into a report project, and I want to populate
I am trying to populate a select list with time. I want to create
I have the following scenario, I want to create a DataGrid and then populate
This is what I want: I had created the top red layout by this
I have created a web-service app and i want to populate my view controllers
My sql table is something like (message,created) I want to select those rows which
I created a NSEvent and I want to post it. How can I do

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.