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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:30:14+00:00 2026-05-28T23:30:14+00:00

In Obj-c when declaring a variable within @interface @interface: NSObject{ MyObject* myObject} @property (unsafe,

  • 0

In Obj-c when declaring a variable within @interface

@interface: NSObject{
MyObject* myObject}

@property (unsafe, nonatomic) MyObject* myObject;

Vs. Only declare it as a property

@interface: NSObject{}

@property (unsafe, nonatomic) MyObject* myObject;
@end

Not declare any var here?

Regards
Christian

  • 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-28T23:30:15+00:00Added an answer on May 28, 2026 at 11:30 pm

    @property defines an interface, not an implementation. In your case, you’re defining a readwrite property. This means that you’re promising to implement -myObject and -setMyObject:. This has nothing to do with ivars.

    Now, the most common way to implement those methods is by having them be backed by an ivar. As a convenience, ObjC lets you automatically generate the required methods with an ivar store using @synthesize myObject=myObject_; This says “create the required methods for the property myObject using an automatically created ivar called myObject_.” The ivar myObject_ is a real ivar, and you can access it normally (though you generally shouldn’t; you should use accessors).

    Instead of using @synthesize, you could just implement -myObject and -setMyObject:. You could even use @dynamic myObject; to tell the compiler “don’t worry about the implementations for this property; it’ll be handled correctly at runtime.”

    There are a few differences between @property and just declaring methods, but in principle, this line:

    @property (nonatomic, readwrite, strong) MyObject* myObject;
    

    is conceptually the same as this:

    - (MyObject *)myObject;
    - (void)setMyObject:(MyObject *)anObject;
    

    Declaring the ivar yourself has no real impact here. You still need to implement the methods somehow. If your named ivar is the same as the ivar @synthesize is using, then @synthesize just won’t create a new ivar.

    As a matter of practice, I discourage people from declaring ivars anymore. I recommend just using public and private properties with @synthesize to create any needed ivars. If you must have a manual ivar for some reason, then I recommend declaring them in the @implementation block rather than the @interface.

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

Sidebar

Related Questions

I have an Obj-C 2.0 class that has an NSMutableArray property. If I use
In an .h file, I am declaring a global variable as: #pragma data_seg(.shared) #ifndef
Below, I'm not declaring my_ints as a pointer. I don't know where the memory
var obj = { MainFunction: function() { AnotherSubFunction: function() { } var variable =
I'm puzzled as to why get(Object obj) does not work with instance variables (instance
obj[i]['Weight'] = parseFloat(0); obj[i]['Height'] = parseFloat(0); obj[i]['Temperature'] = parseFloat(0,10); // This does not work...
Is there any different between declaring event Action<> and event EventHandler<> . Assuming it
MyObject obj = new MyObject(para1); In Java I can always do this while switching
Is there any difference between declaring inherited virtual function in a child class with
Declaring boost::poor is something that goes as below. boost::pool<> Obj(); I am curious how

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.