Where is "setText" truly declared?

Discussion in 'iOS Programming' started by Vidarious, Jul 9, 2011.

  1. Vidarious macrumors newbie

    Nov 27, 2010
    Hi guys, I'm currently learning Objective C for iPhone dev and using a lot of the documentation to help understand the syntax. I've come across a property that I can't find declared anywhere.

    For the class UILabel there is a property called "text". Which you can see in the UILabel documentation. However there is also a property called "setText" which allows you to change a UILabel object. However "setText" is nowhere to be found!

    The quick help for setText is as follows:

    Name: setText:
    Declaration: @property(nonatomic, copy) NSString *text
    Availability: iOS (2.0 and later)
    Abstract: The text displayed by the label.
    Declared in: UILabel.h
    Reference: UILabel Class Reference

    When you look in UILabel.h or the documentation for UILabel there is no such thing as "setText" --- only "text". How can I use "setText" if it isn't declared?
    E. [display setText:[NSString stringWithFormat:mad:"%g", result]]; works fine.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Objective-C Programming Language : Property Declaration Attributes
    The default names for the getter and setter methods associated with a property are propertyName and setPropertyName: respectively—for example, given a property “foo”, the accessors would be foo and setFoo:. ...etc...

    There are not two properties, text and setText:. There is only one property, text. It has a setter accessor named setText:.

    You should read the entire section for Declared Properties.
  3. Vidarious thread starter macrumors newbie

    Nov 27, 2010
    This explains a lot! That explains why I couldn't find an exact declaration or setText.

    Thank you

Share This Page