Obj. C Question

Discussion in 'Mac Programming' started by JOD8FY, Feb 26, 2007.

  1. macrumors 6502a

    JOD8FY

    Joined:
    Mar 22, 2004
    Location:
    United States
    #1
    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.
     
  2. macrumors member

    Joined:
    Apr 28, 2005
    Location:
    Boston MA
    #2
    The answer is in the documentation for NSControl (which NSTextField is a subclass of)


    Code:
    
    int x = [myTextField intValue];
    x++;
    [myTextField setIntValue:x];
    
    
     
  3. thread starter macrumors 6502a

    JOD8FY

    Joined:
    Mar 22, 2004
    Location:
    United States

Share This Page