Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JOD8FY

macrumors 6502a
Original poster
Mar 22, 2004
633
0
United States
Hello all,

I have a simple Objective C question. I am trying to create a relatively simple program in Xcode as my first venture with Objective C. I have only programmed with Java in the past. What I want to do is get the text of a text field, convert it to an int (the text in the textfield is a number) then increase that integer by one and convert it back into a string to be displayed in the textfield. In Java, this is what the code would look like:

Code:
//grab the integer of the text field, it is a string so we convert it to an integer value
                int val=Integer.parseInt(textField.getText());
                val++;
                //Convert val back to a string and put it back in the value textfield
                textField.setText(Integer.toString(val));

What are the commands to do this in Objective C?

Thanks in advance,
JOD8FY :apple:

P.S. - Not sure if this is necessary, but it's programmed in Cocoa.
 

gamera~

macrumors member
Apr 28, 2005
63
0
Boston MA
The answer is in the documentation for NSControl (which NSTextField is a subclass of)


Code:
int x = [myTextField intValue];
x++;
[myTextField setIntValue:x];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.