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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:16:55+00:00 2026-05-30T18:16:55+00:00

What is an actual name of instance variable, say, topSpeed, as from lectures of

  • 0

What is an actual name of instance variable, say, topSpeed, as from lectures of Stanford University about the Objective-C and iOS development?

Here is the code:

@property (nonatomic) double topSpeed;

Looking at this code I will think that I have defined a variable topSpeed in the class.
I can’t understand why it will declare automatically the getter method with the name the same as the variable name – topSpeed?

Another question is when we use

@synthesize topSpeed = _topSpeed

And if we look at what the @synthesize will generate:

- (double) setTopSpeed:(double)speed
{
   _topSpeed = speed;
}


- (double) topSpeed
{
   return _topSpeed;
}

What is _topSpeed here and what is topSpeed? I have declared a variable topSpeed, not the _topSpeed. What if I don’t use property what would the variable name be?

  • 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-30T18:16:56+00:00Added an answer on May 30, 2026 at 6:16 pm

    In the earlier days of Obj-C and still today you declared variables in your class’s header file like so:

    @interface MySubclass : NSObject {
        int varName;
    }
    

    Then you would have to manually create setter and getter methods to access the variable outside your class. In order to help deal with memory management (useful for objects), Apple introduced properties in Obj-C 2.0 and it allowed you to define the accessors for a given variable. You could say that a variable would have certain attributes (such as retaining or copying a value, having alternate setter or getter name, etc) and you defined this like:

    @property (someAttributes) int varName;
    

    then in your @implementation you could @synthesize these properties with the given attributes and the compiler would generate setter and getter methods for your variable.

    @synthesize varName; // Generates -setVarName: and -varName for you
    

    Now, today the idea is that you can move away from implementing the instance variables in the {} section and just declare a property and a synthesize. What we get if we just say

    @property (nonatomic) double topSpeed;
    @synthesize topSpeed;
    

    is a setter and a getter called setTopSpeed: and topSpeed with an instance variable called topSpeed (created by the compiler) to store the value. The idea behind @synthesize topSpeed = _topSpeed; is that the instance variable name will be _topSpeed but the accessor names will still be -setTopSpeed: and -topSpeed. This helps for code readability because there can be confusion between when you say self.topSpeed or topSpeed in your code (the first calls the accessor the second is the ivar). The _topSpeed differentiates itself from normal variables and also makes it explicit when you’re calling self.topSpeed (the accessor) vs _topSpeed (the ivar). Apple is moving to this underscore syntax as well so don’t think that it’s going extinct, because it’s quite the opposite. Update: (See Tommy’s comment)

    It also helps with variable naming collisions. If you had to implement setTopSpeed: yourself it would look something like this:

    - (void)setTopSpeed:(double)topSpeed {
        _topSpeed = topSpeed; // _topSpeed makes it obvious it's an ivar
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this (assume the name variable is receiver): if (!(receiver instanceof
We all know that this refers to the actual instance of a class...but it
Due to some custom components which expect a bean name (NOT the bean instance)
I am attempting to take the Name and ID fields from each object, but
I am some what confused as to the difference between accessing an instance variable
I've seen a lot of questions asked about instantiating classes from a string but
Here's what I want to do: $clsName = substr(md5(rand()),0,10); //generate a random name $cls
I'm having trouble creating an instance of a class using Python's re module. Here's
This ruby/rails construct always puzzles me: User.where(:name => Thiago).limit(3).using(:slave_one) This must execute from left-to-right,
I have a query that looks like the following SELECT t1.Name, t2.ID, t2.name FROM

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.