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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:35:31+00:00 2026-05-13T17:35:31+00:00

I am curious what is happening with setValue:forKey: in the code snippet below: is

  • 0

I am curious what is happening with setValue:forKey: in the code snippet below: is it just setting the pointer to point to each array, similar to …

[self setMyArray_1: animalArray];
[self setMyArray_2: animalArray];
[self setMyArray_3: animalArray];

Also: does setValue:forKey retain the array? I am guessing it does (as the above would)

Code Snippet:

// INTERFACE
@property(nonatomic, retain) NSArray *myArray_1;
@property(nonatomic, retain) NSArray *myArray_2;
@property(nonatomic, retain) NSArray *myArray_3;

// IMPLEMENTATION
@synthesize myArray_1;
@synthesize myArray_2;
@synthesize myArray_3;

for(counter=1; counter<=3; counter++) {
    NSArray *animalArray = [[NSArray alloc] initWithObjects:@"cat", @"rat", nil];
    NSString *propertyName = [[NSString alloc] initWithFormat:@"myArray_%d", counter];
    [self setValue:animalArray forKey:propertyName];
    [animalArray release];
    [propertyName release];
}

gary

  • 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-13T17:35:31+00:00Added an answer on May 13, 2026 at 5:35 pm

    The answer is yes, the two code snippets essentially do the same thing. setValue:forKey doesn’t retain the array, but it finds the synthesized setMyArray_x method which in turn retains the array. iVarName should better be called propertyName or keyName. However, if you hadn’t declared and synthesized the properties, but instead just had four ivars, setValue:forKey would still be able to set them to point to animalArray but it wouldn’t be retained.

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

Sidebar

Related Questions

I am curious to know why this is happening. Please read the code example
Just curious here: is it possible to invoke a Windows Blue Screen of Death
Just curious: 4 instanceof Number => false new Number(4) instanceof Number => true? Why
Just curious. How does actually the function Sleep() work (declared in windows.h)? Maybe not
I am just curious, I am writing some notes for a friend and am
Just curious where CPAN installs all the Perl modules by default in OS X.
Just curious if anyone can explain to me why I can request a page
curious if anyone might have some insight in how I would do the following
Curious to know how people set up their personal and/or work development environment, in
Curious to get people's thoughts. I conduct frequent interviews, and have had enough in

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.