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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:40:39+00:00 2026-05-23T16:40:39+00:00

I think I got a bad book on Objective-C. It said to put variables

  • 0

I think I got a bad book on Objective-C. It said to put variables I’m going to use and make available to other classes inside the interface brackets, and then declare a property of the same thing.

@interface appDelegate : NSObject <UIApplicationDelegate>  {
    NSNumber *myNumberOtherClassesCanUse;
}
@property (nonatomic, retain) NSNumber *myNumberOtherClassesCanUse;

However, I saw another question answered that made me think I didn’t have to put them inside the brackets, so I tried that and it still works fine.

I bought another book and it doesn’t explain it either, so can someone tell me or point me to documentation on when I have to put them inside the brackets AND make them properties?

  • 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-23T16:40:39+00:00Added an answer on May 23, 2026 at 4:40 pm

    A long and complicated answer:

    The class fields, the things inside the interface brackets:

    @interface MyClass : SomeSuperclass
    {
      int someNumber_; /* this stuff */
    }
    

    add actual bytes to your object. An objective-C class is really, underneath all the fluff, just a large C struct; and these are the fields of that struct. (You can even get at them with -> style C pointer syntax, although the compiler will yell at you if you do so without an @public in there; the correct way to access these fields is by bare name like any other variable.)

    A property declaration like:

    @property (nonatomic, assign, readwrite) int someNumber;
    

    is obj-C 2.0 shorthand for a pair of method declarations like:

    -(int)someNumber;
    -(void)setSomeNumber:(int)newNumber;
    

    which adds nothing to your class; it just declares to the world that here are some operations that can be performed on this class. By convention, methods like this are supposed to get and set a field value, or at least behave like they do. Having methods like this lets you use the obj.prop and obj.prop = val dot-syntax to call them.

    A synthesize directive:

    @synthesize someNumber;
    

    optionally creates these methods for you at runtime, using standard builtin behaviors (informed by that “nonatomic, assign” stuff), AND optionally creates a field of the same name to get and set. A directive like @synthesize someNumber = someNumber_; names the created field “someNumber_” instead. If you declared such a field in the @interface block, like I did above, it uses that field; otherwise it quietly inserts an appropriate field of its own. This quiet field insertion is new behavior since the 4.x simulator; before that you had to declare all your fields in the @interface{} block, period.

    In summary: @interface{…} describes the physical fields of your object; @property()… describes ways your object is supposed to be used; and @synthesize is shorthand for implementing basic getter/setters and inserting extra fields if needed. I usually let @synthesize do its thing, and leave my @interface{} block empty until I have an actual need to declare a field explicitly, usually to look at it with the debugger.

    [as of the latest SDKs, some of the above is dated. In particular, @synthesize is now optional, and instance vars can be declared in the @implementation in the .m file.]

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

Sidebar

Related Questions

Today I got this question for which I think I answered very bad. I
Is it considered a bad practice to use code-behind with ASP.NET MVC Views? Got
UPDATE2: I think I got it now: <?php /* * @name Lawler's algorithm PHP
I have studied generators feature and i think i got it but i would
I went through some tutorials on the State monad and I think I got
I think I've got it down to the most basic case: int main(int argc,
I'm trying to design a database for a sports meeting. I think I've got
I've got what I think is a simple question. I've seen examples both ways.
I've got an ssl certificate for what I think is my domain and I
I got over a problem, I think a very specific one. I've got 2

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.