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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:52:53+00:00 2026-05-26T15:52:53+00:00

How can I access @public NSArray or NSMutableArray after updating it? From one class

  • 0

How can I access @public NSArray or NSMutableArray after updating it? From one class to another?

I can access it with calling -(id)init.. when program starts, but if I want to update it later, I get nil. What’s the problem?

Simple example code:

MyFirstClass.h

#import <Foundation/Foundation.h>

@interface MyFirstClass : NSObject
{
@public

    NSArray *testArray;

}

-(IBAction)Button:(id)sender;

@end

MyFirstClass.m

#import "MyFirstClass.h"

@implementation MyFirstClass
- (id)init {
if (self = [super init]) {

    //I can take this Array from here

    //testArray = [NSArray arrayWithObjects: @"first", @"second", @"third", nil];

}
    return self;
}

-(IBAction)Button:(id)sender {

    //How take this Array?

    testArray = [NSArray arrayWithObjects: @"first", @"second", @"third", nil];

}

@end

SimpleClass.h

#import <Foundation/Foundation.h>
#import "MyFirstClass.h"

@interface SimpleClass : NSObject
{
    MyFirstClass *other;
}

-(IBAction)ButtonGet:(id)sender;

@end

SimpleClass.m

#import "SimpleClass.h"
#import "MyFirstClass.h"

@implementation SimpleClass

-(IBAction)ButtonGet:(id)sender {

    other = [[MyFirstClass alloc] init];     

    if(other->testArray) {
        NSLog(@"Working!");
    }
    else { NSLog(@"Not working!"); }

}

@end

Created example has two buttons in *.xib. One button named “Button” (MyFirstClass) and other “ButtonGet” (SimpleClass). So when program starts need to push “Button” and then “ButtonGet”, after that NSLog should write “Working!” if it gets testArray and if not – “Not working!”. It always shows “Not Working!”.

  • 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-26T15:52:54+00:00Added an answer on May 26, 2026 at 3:52 pm

    Welcome to Objective C! If you feel overwhelmed, and would like to read some introductory material, please have a look at the links in Peter Hosey’s excellent “Useful Cocoa/Cocoa Touch Links” card.

    You create the MyFirstClass instance in -[SimpleClass ButtonGet:], and since its testArray member isn’t explicitly assigned to in -[MyFirstClass init], it is (correctly) initialized to nil. It will remain that way forever unless you assign something else to it, but you never do. (You only assign to it in [MyFirstClass Button:], but you never call that method.)

    Other things to consider:

    • Manual memory management requires that you know the Cocoa memory management rules and constantly keep them in mind while writing your code. For example, you need to retain the result of +[NSArray arrayWithObjects:] when you assign it to a member variable, and release it in -[MyFirstClass dealloc]. Similarly, you need to release the other object in -[SimpleClass dealloc].

    • It is much cleaner to use properties (declared using @property) instead of directly referring to another class’s member variables.

    • Please consider following the Cocoa Coding Guidelines and starting your method names with a lowercase letter. It makes your code fit better with the system APIs, and makes it much easier to read for other people.

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

Sidebar

Related Questions

How can I access a variable in one public class from another public class
How can I access a public static member of a Java class from ColdFusion?
In a regular .aspx page, you can access public properties from the codebehind. Is
I can access the database either from a .NET program (using ODBC) or through
I know that I can access a constructor on another constructor like below: public
I can not access public method of my class MyPanel which extends JPanel .
I have a singleton class that inherits from sprite so that it can access
Java Q: I can't access a public variable in my parent's class' inner class
How can hibernate can access a private field/method of a java class , for
I know you can access the Contact Store from the SDk, but is it

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.