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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:19:11+00:00 2026-06-05T12:19:11+00:00

I have few questions to ask about the following class #import <Cocoa/Cocoa.h> @interface SomeObject

  • 0

I have few questions to ask about the following class

#import <Cocoa/Cocoa.h>

@interface SomeObject {
    NSString *title;
}

@property (retain) NSString *title;

@end




   implementation SomeObject

    @synthesize title;

    -(id)init {
        if (self=[super init])
        {
            self.title=[NSString stringWithFormat:@"allyouneed"];
        }

        return self;
    }

-(void)testMethod{
self.title=[[NSString alloc] init] ;
}

    -(void)dealloc {
        self.title=nil;

        [super dealloc];
    }
  1. In the .h file do we need to declare the title and sub when we add the property. is it not enough to add the @property (retain) NSString *title; line.

2.Do i need to autorelease both assignment to title in the init and testMethod. if So why?

Can some one explain these things to me.

  • 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-05T12:19:13+00:00Added an answer on June 5, 2026 at 12:19 pm

    1-
    You don’t need to declare the iVar in the header. You might also use

    @synthesize myVar = _myVar;
    

    if you want to go for a different iVar name

    2-
    Declaring a property “retain” means that every time you assign the property with a new object, it automatically releases the previous object and retain the new one.

    Therefore, if you use a convenience method like stringwithFormat, the property will retain that object for you.

    If you want to use alloc-init, for me the best way to do is:

    NSString *str = [NSString alloc] init];
    self.title = str;
    [str release];
    

    Besides, it is right to assign nil to the property in the dealloc because the property will release the object it has, and it calls retain on nil which doesn’t do anything

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

Sidebar

Related Questions

I have a few questions about the eq() property of jQuery and how to
I have quite a few questions to ask about these issues. I'm an intern
I have a few questions I would like to ask about string literals and
I have few questions about using lock to protect my shared data structure. I
I have a few questions about Xcode and interaction with GCC 4.2.1: It doesn't
I have a few questions about this after reading the iPhone documentation on it:
I have a few questions about cross-page posting in ASP.NET: What is cross-page posting
I have a few questions about Core Location. 1) Should the user refuse permission
I'm new in android and I have few questions to ask. Is it possible
I have a few questions about endian-ness that are related enough that I warrant

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.