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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:31:04+00:00 2026-06-16T02:31:04+00:00

I am learning Objective-C and was just curious. I can create an object of

  • 0

I am learning Objective-C and was just curious. I can create an object of a NSString in these places, and please provide any others. To me they all do the same thing. I don’t know what is the difference is between them. Where is it stored? From where can I access it? What are the advantages?

1)

// .h
@interface ...
@property (strong,nonatomic) NSString *text;
@end

2)

// .h
@interface ... { 
NSString *text
}
@end

3)

// .m
@interface ... ()
@property (strong,nonatomic) NSString *text;
@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-16T02:31:05+00:00Added an answer on June 16, 2026 at 2:31 am

    First and foremost, my answer is based on the latest Clang compiler, older versions worked slightly different.

    So, you’re not creating an object in neither. You’re not even declaring an object in two of them.

    In the first case, you’re actually telling the compiler that you need to expose a property called text of type NSString. What the compiler does, is declaring an instance variable for you _text (which you can access without a problem by the way) and the methods needed to get and set that instance variable. As you can see the storage is still internal, you just have getters and setters set for you.

    In the second case you’re actually declaring an instance variable (ivar) yourself, just as the compiler does with _text. It’s accustom to prefix it with _. The storage is still internal. On top of that, you can’t access your ivar from outside, since it has no getter or setter and the implicit declaration is @private.

    In the third case, you create an anonymous category (thus the empty parentheses) which adds a property to your class. Storage for this is a little bit harder/longer to explain, if you are curious about it, you can search up the Apple docs, see what a category is and so on. You can only access your property from within your class in this case, which makes it somehow redundant (the getters and setters), you could have declared it as an ivar.

    You can also declare your ivars like this:

    @interface GenericViewController : UIViewController{
        NSString * text;
    }
    
    @end
    
    
    
    @implementation GenericViewController{
        NSString * text;
    }
    
    @end
    

    Both of the above have local storage and private visibility (can’t be accessed from outside). The difference between the two is that instance variables declared in the implementation are implicitly hidden and the visibility cannot be changed with @public, @protected and @private. If you use those directives you won’t get compiler errors but are ignored.

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

Sidebar

Related Questions

I am just learning objective-c but can't figure out whats wrong with my code
I'm just learning Objective-c and I am trying to create a class the generates
I just started learning Objective-C yesterday, and i can't quite figure out this warning:
Ok so I've just started learning java (I usually program in Objective-C). My first
I'm learning Objective-C, and have a C/C++ background. In object-oriented C++, you always need
I'm learning Objective-C using GNUstep(because I use Linux). I was thinking in create a
I've just started learning Objective-C. I'm doing one of the standard calculator exercises. It's
I'm just learning some basic programming in Objective C and Cocoa. I'm trying to
I am just learning objective-c and iPhone development, and I am really struggling with
I've just started learning Objective C and getting a bit stumped with arrays. Basically,

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.