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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:41:49+00:00 2026-06-18T02:41:49+00:00

I have declared a variable in .h: @property (nonatomic, retain) NSString *var; When i

  • 0

I have declared a variable in .h:

@property (nonatomic, retain) NSString *var;

When i call a property variable using:

 _var = sumthing;

the app crashes and when i call it as:

 self.var = sumthing;

it works well.

Is there any difference in these two scenarios?

NOTE: I have not used @synthesize as it is not required to write this specifically.

  • 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-18T02:41:50+00:00Added an answer on June 18, 2026 at 2:41 am

    You should use self.var to retain sumthing when you are using @property so that it calls the setter method internally to retain it. If you are directly assigning it, the setter method wont be called and it will crash when sumthing is released.

    Basically a self.var = sumthing; is equivalent to assigning sumthing to var and then retaining it(var = [sumthing retain];). When you are directly doing it, it just does the assigning part and not the retaining. So when sumthing gets released, you will be pointing to a released variable when you use var and your app crashes.

    If you still want to use it without using self.var, you can try with _var = [sumthing retain]; which could work.

    This has nothing to do with synthesize since you dont need to use it anymore. You can skip it.

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

Sidebar

Related Questions

I have a variable declared like this: @property (nonatomic, retain) NSMutableArray *aInfo; At the
I have a NSString declared in the interface part: @property (nonatomic, retain) NSString *filePath;
I have an NSString declared as @property (nonatomic,copy) NSString *text in a class. When
I have a NSMutableArray property declared as (nonatomic, retain) called Categories. In dealloc, I
I have declared a variable NSString sessionId; in app delegate file for global usage.
I have a instance variable declared as a retain property & then I released
I have declared this variable in jquery var enabled = false; I want to
if i have an outlet variable which i've declared as a property @interface MyClass:UIViewController
I have an IBOutletCollection of UIButtons: @property (nonatomic, retain) IBOutletCollection(UIButton) NSMutableArray *Buttons; with an
I have a weird problem. pictureLink is a global variable declared in .h NSString

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.