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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:53:40+00:00 2026-06-17T18:53:40+00:00

I have got a header file (.h) and I want to declare name but

  • 0

I have got a header file (.h) and I want to declare name but all these ways work the same I think because I haven’t seen any difference with functionality. Could you tell me what the difference is between:

This with both declarations:

@interface someClass : UIViewController
{
    NSString *name;
}

@property (nonatomic, copy) NSString *name;

@end

Without variable:

@interface someClass : UIViewController
{

}

@property (nonatomic, copy) NSString *name;

@end

Or Without property:

@interface someClass : UIViewController
{
    NSString *name;
}

@end
  • 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-17T18:53:41+00:00Added an answer on June 17, 2026 at 6:53 pm
       @interface someClass : UIViewController
       {
         NSString *name;
       }
    
       @property (nonatomic, copy) NSString *name;
    
       @end
    

    Doing this you will explicitly declare both a property and an ivar.

    A property is just a set of methods:

     - (void)setName:(NSString*)name;
     - (NSString*)name;
    

    An ivar is the memory store holding the value that the property methods manage. This allows you to do:

    self.name = ... // access through setter method
    name = ... // direct access
    

    The advantage of using properties is that they deal with memory management for you. E.g., in your case, the property is of type copy: this means that with the first syntax (self.name = ...) a copy of the object will be done. If not using properties, you would explicitly need to do: name = [originalString copy]; to obtain the same effect.

    Other options you can specify for properties (but not ivars) are: strong and weak ownerships.

    Furthermore, a property also represents a public interface to access the variable from outside your class.

    Using direct access you are on your own as to memory management (if you are not using ARC).
    If you are using ARC and don’t define properties, you will not be able to control how the memory is managed by specifying the ownership: strong, weak, retain).

     @interface someClass : UIViewController
     {
    
     }
    
     @property (nonatomic, copy) NSString *name;
    
     @end
    

    Here you only declare the properties; the ivar is "inferred" by the @synthesize directive in your implementation file. This is only possible in Objective C 2.0 and later (previously, the ivar declaration as above was mandatory).

    The same considerations as above applies, with a minor nuance: with older versions of LLVM (ObjC compiler) you will not be able to reference directly the auto-synthesized ivar; with current version of LLVM, if you omit the @synthesize directive, then an automatic ivar named after your property would also be declared (in your case it would be _name).

    This last paragraph may seem a bit "advanced", or contrived, but you can safely ignore it.

     @interface someClass : UIViewController
     {
        NSString *name;
     }
    
     @end
    

    In this case you are only declaring the ivar. No accessor methods. You will need to handle memory management on your own (if not using ARC), futhermore you will not be able to access the variable from outside the class. For that you need accessors.

    Hope this helps.

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

Sidebar

Related Questions

I've got a class A defined in a separate header file. I want class
i have a header file named NetworkInterfaceInfoProvider.h. in this header file i declare a
I have got following file: file.csv header:2013/01/01, shasum: 495629218484151218892233214 content:data,a,s,d,f,g,h,j,k,l content:data,q,w,e,r,t,y,u,i,o,p content:data,z,x,c,v,b,n,m footer:2013/01/01 EOF
I've got an interesting box-model problem here. I have a header full of links,
Have got an NSString *str = @12345.6789 and want to find out if there
I have got the requirement to find the core file in multiple box/machine and
I have a class which get all the bytes from a file, then it
I think I have an issue with terminating my strings, because I'm having trouble
I have currently got a UITableView in my main view controller. I want the
I have got an SQLite3 Database with several images in it. I want to

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.