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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:15:18+00:00 2026-06-01T23:15:18+00:00

I have a class with a NSArray property using ARC with nothing fancy… #import

  • 0

I have a class with a NSArray property using ARC with nothing fancy…

#import <Foundation/Foundation.h>
@interface MyClass : NSObject
property(nonatomic, strong) (NSArray *) myArray;
@end

#import "MyClass.h"
@implementation MyClass
@synthesize myArray = _myArray;
@end

If an attempt is made to use a method inside of another class to try to set that array it does not set it if only the array is passed; however, it does set if the class is passed, I’m not sure why that is….

The code that attempts this both ways is below…

MyClass *myClass = [[MyClass alloc] init];
[self setArrayByPassingArray:myClass.myArray];
NSLog (@"%@", myClass.myArray)
//result is null

[self setArrayByPassingClass:myClass];
NSLog (@"%@", myClass.myArray)
//result is test, test2...

-(void)setArrayByPassingArray:(NSArray *)arrayToSet {
arrrayToSet = [[NSArray alloc] initWithObjects: @"test", @"test2", nil];
}

-(void)setArrayByPassingClass:(MyClass *)classWithArrayToSet {
classWithArrayToSet.myArray = = [[NSArray alloc] initWithObjects: @"test", @"test2", nil];
}

I tried some other methods with just strings and the strings are not changed, so I’m not sure why they are changed if class containing them is passed…

  • 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-01T23:15:20+00:00Added an answer on June 1, 2026 at 11:15 pm

    Your setArrayByPassingArray: method in the first example assigns the newly created NSArray to its parameter, which is passed by value, and is promptly discarded upon exiting from the method. What happens here is that a copy of the reference to myArray is made (not a copy of the array, only a copy of a reference to that array) before calling setArrayByPassingArray:. That copy is no longer attached to the myArray member of MyClass.

    Your second example is not passing a class – it’s passing an instance of the class, and then it correctly uses the dot notation to assign the myArray property in your instance. That’s why this second example works, and the first example does not.

    If you use NSMutableArray instead of NSArray throughout your program, you can rewrite your first example to make it work:

    -(void)setArrayByPassingArray:(NSMutableArray *)arrayToSet {
        [arrrayToSet setArray:[[NSArray alloc] initWithObjects: @"test", @"test2", nil]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> @interface Bankdaten : NSManagedObject @property
I have the following class: @interface Topics : NSObject { NSNumber * _until_id; NSArray
I have a class, let's call it ABC, with an NSArray *objects property, and
I have a property in my class, which is an NSArray. I am retaining
My class structure looks like this: TargetDetail : NSObject @property Target *target Target :
I have a class MyCLController with a property dataSource that is data source delegate
I have a Car class. It's got a property called enginePower. On the other
I have an unordered array of instances of the following class: @interface Place :
I have a class A with a property NSString *name . If have an
I have a class that im using and cant get the code to fire

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.