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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:19:52+00:00 2026-06-03T21:19:52+00:00

For the following code snippet from ViewController.m: – (IBAction)buttonAction:(id)sender { CustomButton *button = (CustomButton

  • 0

For the following code snippet from ViewController.m:

- (IBAction)buttonAction:(id)sender
{
    CustomButton *button = (CustomButton *)sender;
    button.associatedObject = [self.sourceOfObjects.objectArray lastObject];
    [self.foo.arrayOfObjects addObject:button.associatedObject]; // this does not work?
}

• CustomButton is subclass of UIButton and has @property (nonatomic, strong) associatedObject that is a pointer to an object of type NSObject.

• sourceOfObjects is a @property (nonatomic, strong) of self of type MyCustomObject, a subclass of NSObject.

• objectArray is a @property (nonatomic, strong) of sourceOfObjects of type NSMutableArray.

• foo is a @property (nonatomic, strong) of the ViewController of type MyCustomObject, a subclass of NSObject.

• arrayOfObjects is a @property (nonatomic, strong) of foo of type NSMutableArray.

QUESTION: Any idea why I cannot add the pointer from button.associatedObject to self.foo.arrayOfObjects so that I have a pointer in self.foo.arrayOfObjects that points to the same object as button.associatedObject?

WHAT I EXPECT TO HAPPEN: If I subsequently ask for [self.foo.arrayOfObjects lastObject], it should return the object that button.associatedObject also points to.

WHAT ACTUALLY HAPPENS: Subsequently asking for self.foo.arrayOfObjects.count returns 0. I do not believe it is an issue with initialization of arrayOfObjects as I have lazy instantiation in place.

I hope I phrased this question accurately, tried to be precise. 🙂

  • 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-03T21:19:56+00:00Added an answer on June 3, 2026 at 9:19 pm

    I forgot to add lazy instantiation for self.foo.arrayOfObjects within the definition for class MyCustomObject. :S What that means is that within file MyCustomObject.m the following lines were missing:

    - (void)setArrayOfObjects:(NSMutableArray *)arrayOfObjects
    {
        _arrayOfObjects = arrayOfObjects;
    }
    
    - (NSMutableArray *)arrayOfObjects
    {
        if (!_arrayOfObjects) _arrayOfObjects = [[NSMutableArray alloc] init];
        return _arrayOfObjects;
    }
    

    Because arrayOfObjects was not lazily instantiated within the MyCustomObject class, adding an object to self.foo.arrayOfObjects from within ViewController.m did nothing because self.foo.arrayOfObjects was still null, and adding an object to null procures a null object.

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

Sidebar

Related Questions

The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk
From the book Groovy and Grails recipes I'm using the following code snippet: String
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I have the following snippet from my code: switch ($extention) { case gif: $src
Hey all, the following is a snippet of code taken from the unix ptx
I have the following code snippet from my PowerShell script that... Loops through a
the following code snippet taken from http://perldoc.perl.org/perlrequick.html#Search-and-replace gives me Bareword found where operator expected
I have written the following code snippet to read data from the database :
I have used the following code snippet to logout the user from the session.
I have the following code snippet, which loads data from a CSV file into

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.