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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:36:25+00:00 2026-06-11T22:36:25+00:00

Here is 2 code snapshot- @interface A:NSObject { NSMutableArray *a; } @property (retain) NSMutableArray

  • 0

Here is 2 code snapshot-

@interface A:NSObject
{
     NSMutableArray *a;
}

@property (retain)   NSMutableArray *a;


@implementation

@synthesize a;

-(id)init
{
      if(self=[super init])
     {
            a=[[NSMutableArray alloc] init];
     }
}

@end


@interface A:NSObject
{
     NSMutableArray *_a;

}

@property (retain)   NSMutableArray *a;



@implementation

@synthesize  a=_a;

-(id)init
{
      if(self=[super init])
     {
            _a=[[NSMutableArray alloc] init];
     }
}

@end

Now what i need to know, is in both code instance variable assigned value directly rather than using accessor and retain count is 1? Or there is difference between them. Thanks.

And one more things, apple recommended not to use accessor in init/dealloc, but at the same time ask not to directly set iVar. So what is the best way to assign value of ivar in init()??

  • 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-11T22:36:27+00:00Added an answer on June 11, 2026 at 10:36 pm

    ARC vs non-ARC

    First, you should decide whether you want to use automatic reference counting (ARC) or manual reference counting. It looks like you’ve chosen the latter – which is fine because you can always transition to ARC later.

    Property attributes/setter semantics

    You have marked the setter semantics for the property a as retain. This will work; but since the property is exposed in the class interface, class users may use it to set the _a ivar. Since class users may not expect your class A to directly modify the the NSMutableArray instance they passed, better to use copy semantics for mutable object properties.

    Property access in init and dealloc

    Use of declared properties in init and dealloc is often discouraged because doing so may have side effects due to KVO. These side effects may not work well with a partially constructed or partially deconstructed object.

    Your questions

    Here’s what I would do:

    // assumes Xcode 4.4+ for autosynthesize
    @interface A:NSObject
    @property (nonatomic,copy) NSMutableArray *a;
    @end
    
    @implementation A
    
    - (id)init {
        self = [super init];
        if( !self ) return nil;
    
        _a = [[NSMutableArray alloc] init];
    
        return self;
    }
    @end
    

    EDIT:

    Or, if auto synthesize is not available:

    @interface A:NSObject
    @property (nonatomic,copy) NSMutableArray *a;
    @end
    
    @implementation A
    
    @synthesize a = _a;
    
    - (id)init {
        self = [super init];
        if( !self ) return nil;
    
        _a = [[NSMutableArray alloc] init];
    
        return self;
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the snapshot of repeater code. I have problems with geting all the
Here is a snapshot of my code: $fetchPictures = $PDO->prepare(SELECT * FROM pictures WHERE
Here's the snapshot of the code: If the function testFields at Line:3 returns false,
The code is: @interface RouteMapAnnotation : NSObject <MKAnnotation> { CLLocationCoordinate2D coordinate; NSString* title; NSString*
Here's a snapshot of my HTML code as viewed after clicking View Source in
The script is on jsfiddle here : CODE What it does at the moment
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code my jqgrid editing through form. $(#DataEnergy).jqGrid('navGrid', '#pagergrid', {}, //options {editdata: {
Here my code, I need to insert into mysql database I have mysql,php,android 1)
Here is code from MSDN . I don't understand why the work isn't just

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.