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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:40:47+00:00 2026-05-24T09:40:47+00:00

I want to be able to access an array of objects in my iPhone

  • 0

I want to be able to access an array of objects in my iPhone application. The array of objects is populated in the appDelegate of my application and I want to be able to access the array in one of my View Controllers.

I currently set up the array in my appDelegate.h file as follows:

NSArray *listObjArray;
@property (nonatomic, retain) NSArray *listObjArray;

I then populate it with some Strings like this in the AppDelegate:

listObjArray = [NSArray arrayWithObjects:@"Hello", @"How", @"are", nil];
NSLog(@"Array size = %i", [listObjArray count]);

It is synthesized and also released in dealloc. The NSLog returns the correct count here.

In my ViewController class I import the appDelegate like this:

#import "MyaAppDelegate.h"

I then access my appDelegate and the NSArray like this and try to Log the count in my View Controller:

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

NSLog(@"Before array set");
NSArray *newArray = [appDelegate listObjArray];
NSLog(@"After array set");
NSLog(@"array count = %i", [newArray count]);
NSLog(@"After array count");

The logging here gets to “After array set” and then I get “EXC_BAD_ACCESS” on the line where I try to print the count from the array in the View Controller.

The printing of the count works fine from the appDelegate and setting the newArray as the array from the delegate appears to work yet I cant do anything with it then.

Can anyone see what I am doing wrong?

  • 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-24T09:40:49+00:00Added an answer on May 24, 2026 at 9:40 am

    You have a memory issue: listObjArray = [NSArray arrayWithObjects:@"Hello", @"How", @"are", nil]; sets the instance variable directly. Shortly after this line the array gets released again, which results in you accessing a bad memory location in NSArray *newArray = [appDelegate listObjArray];, since it has been freed.

    Use self.listObjArray = ... instead when populating the array. This will properly retain the object for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a user to be able to access objects (could be JSON or
Say I have an array of objects that I want to be able to
I want to be able to access custom URLs with apache httpclient. Something like
I want to be able to access some device specific data while running an
I want to be able to access properties from a JSON string within my
I am creating a WebUserControl in ASP.net and want to be able to access
I am dealing with image buffers, and I want to be able to access
I'm importing some XML to C#, and want to be able to access data
I want a grails service to be able to access Domain static methods, for
I want only a (faculty) group of users to be able to access a

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.