Here is how to set the text in an NSTextField programatically in Xcode while developing applications for OSX?

Here is step wise how to set text in NSTextField programatically,

If you are using storyboards for app development.
Connect button storyboard to code class file i.e. .h header & .m method file or incase of swift class file of source code

Let assume that you have connected your NSTextField / Label as:


@property (nonatomic, assign) IBOutlet NSTextField *namedTextField;

So you will use dot operator called .stringValue & Here is how it can be done two ways:

First Way:


self.namedTextField.stringValue = @“App Name”;

Second Way:


[self.namedTextField setStringValue:pointerName];

Precaution: Make sure your textfield variable is not null

Hope it helps,

Thanks & Regards
Mandar Apte

Leave a Reply

Your email address will not be published. Required fields are marked *