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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:49:39+00:00 2026-06-05T08:49:39+00:00

I’m sure this is an complete Noob question… but I’ve actually never had to

  • 0

I’m sure this is an complete Noob question… but I’ve actually never had to deal with this scenario before so I’m a bit befuddled…

Let’s say I have a custom object I’ll call person, and each person object can have an array of “possessions”, a kind of inventory if you will. I would set it up like this:

interface person : NSObject {
    NSString *name;
    NSMutableArray *posessions;

@property (copy) NSString *name;
@property (copy) NSMutableArray *posessions; // no idea if this is even necessary...

}

Of course, I would also synthesize my properties in the implementation file… Now, in my actual controller object, I would make an instance of my object (or usually an array of instances, but for this example, one will work fine…) as so:

person *aPerson;

I know that to access the persons name, I could make a call like this:

[aPerson setName:@"Bob"];

and to retrieve that name, I might use this:

aVar = [aPerson name];

What I’m stuck on is how exactly would I go about adding or retrieving objects to the NSMutableArray located inside my person class? Let’s say I want to use the “count” method for the NSMutable Array.

I’ve done some trial and error with attempts such as:

[aPerson.posessions count];
[[aPerson posessions] count];

Likewise, to add an object to an array, I have often used:

[someArray addObject:anObject];

but attempts like this haven’t worked:

[aPerson.posessions addObject:anObject];

After reading up a bunch and searching the web, I can’t seem to find exactly how to interact with this NSMutableArray in my custom class. I’m sure it’s something obvious that I’m just not quite getting, and it’s become a sort of mental block…

Also, am I correct in synthesizing accessor properties for the NSMutableArray? If so, setX and X don’t seem to be quite so obvious with NSMutableArray… unless they simply copy the entire array into a local variable…

Perhaps is this what needs to be done? use the accessor methods to get the entire array, place it in a local variable, make my changes, then use the set accessor method to put the entire array back into my person object?

Can someone enlighten me a bit on the syntax I should be using here?

* EDIT *

I thought I’d add a bit of clarification to this question. My custom objects (in the above example, my person object) are basically database records. I have several databases I am working with in my project, so for example:

Person – a custom sub-class of NSObject containing multiple NSString Objects, as well as Ints and BOOLs.

personDatabase – An Array of Person objects (set up and controlled within my main CONTROLLER object)

All of the set and get methods are called from “Controller”.

What I have been attempting to do is to directly access the individual objects contained within the personDatabase from within my Controller object. I have done this by declaring another object this way:

Person *activePerson;

Then, all of my calls are made to the currently active Person record (the one currently selected from the personDatabase), such as:

someOutput = [activePerson name];

etc.

Is there a way to directly access the objects inside the NSMutableArray object inside the activePerson object from my Controller object?

  • 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-05T08:49:40+00:00Added an answer on June 5, 2026 at 8:49 am

    You’ve specified the ‘possessions’ property as ‘copy’. Therefore, when you write aPerson.possessions you are getting a copy of the possessions array. The call to addObject adds anObject to a new array that is a copy of aPerson’s array of possessions. The simplest ‘fix’ would be to change ‘copy’ to ‘retain’ (and probably ‘readonly’). [Edit: Wrong; it is ‘copy on assign’ – not ‘copy on read’]

    However, there is a bigger issues. A person has possessions but how you store them is an implementation detail. When you put NSMutableArray in the public interface you overly restrict your implementation. You might be better served to change the Person interface along the lines of:

    @interface Person : NSObject {
    @private
         NSString *name;
         // ...
      }
      - (Boolean) addPossession: (NSObject *) obj;
      - (Boolean) remPossession: (NSObject *) obj;
      - (Boolean) hasPossession: (NSObject *) obj;
      - (NSArray *) allPossessions;
    @end
    

    Then, how you implement these possession methods depends on if you use an array, a set, a linked-list, a tree, a whatever.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but

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.