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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:06:16+00:00 2026-06-03T07:06:16+00:00

I recently picked up the BigNerdRanch book on Cocoa for Mac OSX and am

  • 0

I recently picked up the BigNerdRanch book on Cocoa for Mac OSX and am looking for a good explanation around the use of asterisks * and underscores _ that seem to be inconsistently used throughout the language. Some examples:

These appear to be functionally equivalent:

NSString* myString;
NSString *myString;

Sometimes new variables get an underscore, while others dont:

NSString _myString;
NSString myString;

And sometimes it gets all crazy:

NSString *myString;
NSString *_myString;

I’ve also seen variations with asterisks in methods:

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender
            willSpeakWord:(NSRange)characterRange
                 ofString:(NSString *)string;

So what is the functional use of the asterisk or the underscore, when should you use (or not use) either, and when should they be used in combination?

  • 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-03T07:06:18+00:00Added an answer on June 3, 2026 at 7:06 am

    The * indicate a pointer, which all Objective-C objects are. (You pass around pointers to these objects in memory). At a basic level these are normal C pointers. If I remember correctly You could access some data in an Objective-C object by going object->data, just like you do with pointers to C structs.

    The _ is a Cocoa (and some other languages) convention, meaning “a piece of data that should be considered private to this object”.

    Objective-C has a @private declaration, but it’s also a relatively new addition to the language – if your code is more than 2 or 3 years old (or targeting much older versions of OS X) it might not use @private

    Because of this initial lacking of language infrastructure, the _ is (often) used by the Cocoa community to mark “Hey, you probably shouldn’t set or read this directly, please”.

    So:

    • When dealing with Objective-C classes you always need the * to follow the class name (like NSString), because they are always pointers. I’m confused about your NSString somestring line in your code – either that’ll generate a complier warning or will crash when you try to use it
    • The _ indicates private data. You would do something like NSString* _name in a @interface section of your Objective-C class. You would use _name by itself if you were calling or operating on that data in a method in your class.

    So say you created a Student class:

    // Student.h
    @interface Student : NSObject {
      NSString* _name;
    
    }
    
    - (NSString*) name_as_caps;
    @end
    
    
    // Student.m
    
    @implementation Student
    - (NSString*) name_as_caps {
       return [_name uppercase];
    }
    

    Here we declare a class with a “private” data member: _name. Our Student class needs to return this capitalized for some reason, so we created a method to do that, where we use _name and call the uppercase method on it.

    We needed to refer to the type (or class name) or _name a few times here: once, to declare the variable. For name_as_caps we needed to say: this method returns a pointer to an NSString object, thus we used NSString *.

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

Sidebar

Related Questions

I'm looking for data that looks like abc/def . There may be whitespace around
I recently answered a question, that in its comments section picked up a query
I have recently picked up a project from a few months ago. Went to
Recently i've picked up my EF 4.1 / MVC 3 project again and started
We recently attempted a large, cherry picked merge. First we did a full merge
Recently I was asked to develop an app, which basically is going to use
Recently, I was writing a class in which I discovered that I could reduce
I recently picked up a copy of Applied Cryptography by Bruce Schneier and it's
I've recently picked up Java and have run into a problem. I have several
I've recently picked up Michael Abrash's The Zen of Assembly Language (from 1990) and

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.