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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:50:32+00:00 2026-05-18T03:50:32+00:00

aclass.h @interface aClass : NSObject { NSString *name; } @property (nonatomic, retain) IBOutlet NSString

  • 0
aclass.h

@interface aClass : NSObject {
    NSString *name;
}

@property (nonatomic, retain) IBOutlet NSString *name;

@end

aclass.m 

@implementation aClass

@synthesize name;

- (void)dealloc {
    [name release];
    [super dealloc];    
}

- (void)test1 {
    name = @"hello";
}

- (void)test2 {
    self.name = @"hello";
}

Take above as an example. Could someone please explain the difference between name = @"hello" and self.name = @"hello"? Thanks!

EDIT: Follow-up question: How to write my own setter for an ivar, i.e.: self.ivar = …?

  • 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-18T03:50:33+00:00Added an answer on May 18, 2026 at 3:50 am

    BE AWARE, THIS POST IS OLD !

    This post is from the previous decade.

    Be sure to read the important footnote down below, cheers!!


    It’s really difficult to understand all this, when you’re just getting started.

    Here are some SIMPLE, PRACTICAL rules of thumb FOR BEGINNERS.

    To repeat, this post is FOR BEGINNERS.

    The aim here is to allow you to quickly move from the starting line, to being able to confidently use the system in most situations.

    Later, you can really learn about the inner workings of these issues.

    (1) Don’t ever say name=@"hello". Always say self.name=@"hello". Do a project-wide search for name and ensure you always say self.name and not name, when you set it or change it.

    (2) You know all that infuriating stuff about memory management, initialising, releasing and so on. If you use the self thingy, it takes care of all that for you. Cool huh?

    (3) The self thingy is particularly useful because you can easily "change" the string (or whatever it is) as you go along. So, it’s totally OK to do this,

    self.name=@"aa";  
    self.name=@"bb";  
    self.name=@"cc";  
    

    whereas (in a word) you can never, ever, for any reason, do this…

    name=@"aa";
    name=@"bb";
    name=@"cc";
    

    ( * ) Regarding your literal question, "please explain the difference between name = @"hello" and self.name = @"hello"?" This is easy to do.

    The first one is just setting a variable. You know, exactly like "x=42" in the old days when life was simple and we were 13 years old.

    The second one is completely different, specifically it is calling a complicated routine (known as "the setter") to do a whole lot of amazing and astonishing stuff for you.

    So that is the literal answer to your question. The first one just sets the variable (and don’t forget, there are a whole lot of pointers and other weird stuff involved, and as a rule you certainly can not just set pointers willy-nilly like that). The second one actually calls a big complicated routine and hence does a whole lot of stuff for you.

    Once again, the second one is exactly like saying…

    [name bigComplicatedRoutineHere:@"hello"];
    

    …it is very helpful to always remember that the syntax self. ... is literally calling a routine.

    Indeed, some thinkers on the topic thought it was a dumb idea when they introduced this self.X syntax to mean [X complicatedThingHere]. It introudces a lot of confusion, and every beginner asks exactly what you are asking.

    Personally, it took me over nine years to get this clear in my head. 🙂 So again, I emphasise that you must remember that when you say self.x, in fact, you are actually calling a routine.

    To repeat: the "self dot" syntax in fact calls a routine. (Indeed I believe one of the preprocessors simply expands it to [x amazingStuffHere]. )

    I have tried to answer in a way that will keep you going and allow you to advance and use more features, while you learn about memory management, properties, and so on. If you are more advanced than this post, just ignore it.

    Please note that this post is meant to be advice for beginners to enable them to keep going and not get infuriated. Hope it helps!


    2014 update! Important Note on ARC for beginners …

    Note, this post is five years old now! It’s been read by thousands of beginners and there have been many followup questions etc. Please note that, today in the new "ARC world". To some extent: if you’re a beginner: you should pretty much only use!! properties. ie, use "self.whatever" at all times, everywhere. In any event, just be aware that the information in this post is "largely historic" and is becoming more so every day. Of course, it goes without saying that once you are an expert, you will need to and will understand every subtle detail of all this. Hope it helps someone.

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

Sidebar

Related Questions

I have a class Animal and an interface it inherits from IAnimal. @MappedSuperclass public
I would like a class to implement an interface, I do not want to
While designing an interface for a class I normally get caught in two minds
If I have a class that needs to implement an interface but one or
I want to have a class which implements an interface, which specifies the specific
I have a class with both a static and a non-static interface in C#.
I'm programming a class that implements the observable pattern (not the interface) and I'm
How do I setup a class that represents an interface? Is this just an
I'm currently writing a class that implements the SeekableIterator interface and have run into
I've a class which is a wrapper class(serves as a common interface) around another

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.