Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value from NSTextField

I have an NSTextField and I need to get the field's value into a variable. What's the appropriate method?

like image 284
anakin Avatar asked Jun 12 '09 05:06

anakin


2 Answers

For an NSString you would use:

NSString *myString = [theTextField stringValue]; 

For an int you would use:

int myInt = [theTextField intValue]; 

There are many other methods for getting the value from a control. Have a look at the NSControl reference for more info, under the "Getting and Setting the Control’s Value" section.

Here's a list:

  • doubleValue
  • floatValue
  • intValue
  • integerValue
  • objectValue
  • stringValue
  • attributedStringValue
like image 111
toholio Avatar answered Sep 21 '22 11:09

toholio


Swift 3.x Version:

myField.stringValue 
like image 41
Stanley Avatar answered Sep 20 '22 11:09

Stanley