I have an NSTextField
and I need to get the field's value into a variable. What's the appropriate method?
Macos – Get value from NSTextField
cocoamacosnstextfield
Related Question
- Cocoa: What’s the difference between the frame and the bounds
- Macos – How to set the text in an NSTextField
- Ios – Xcode – How to fix ‘NSUnknownKeyException’, reason: … this class is not key value coding-compliant for the key X” error
- Macos – Find (and kill) process locking port 3000 on Mac
- Cocoa – Text change notification for an NSTextField
Best Solution
For an
NSString
you would use:For an
int
you would use: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