Convert Mac code to iOS

Discussion in 'iOS Programming' started by abcdefg12345, Apr 11, 2014.

  1. abcdefg12345 macrumors regular

    abcdefg12345

    Joined:
    Jul 10, 2013
    #1
    I have a mac app and i want to make iOS version of it but my problem is i can't figure out how the coding work in iOS anyone know of an easy way to write iOS code for example combining 2 fields and displaying them into the third field i use for mac

    .h
    Code:
    @property (weak) IBOutlet NSTextField *Field1;
    @property (weak) IBOutlet NSTextField *Field2;
    @property (weak) IBOutlet NSTextField *Answer;
    - (IBAction)Calculate:(id)sender;
    .m
    Code:
    - (IBAction)Calculate:(id)sender
    {
        float result = [_Field1 floatValue] + [_Field2 floatValue];
        [_Answer setFloatValue:result];
    }
    is there something similar to that for iOS
     
  2. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    :%s/NS/UI/g

    Pretty much the same.

    If you don't know vi, that's code for "replace all occurrences of NS with UI".
     
  3. abcdefg12345 thread starter macrumors regular

    abcdefg12345

    Joined:
    Jul 10, 2013
    #3
    heres what i did

    .h
    Code:
    @property (weak, nonatomic) IBOutlet UITextField *Field1;
    @property (weak, nonatomic) IBOutlet UITextField *Field2;
    @property (weak, nonatomic) IBOutlet UITextField *Field3;
    @property (weak, nonatomic) IBOutlet UIButton *Button;
    .m
    Code:
    - (IBAction)Button:(id)sender
    {
       float result = [_Field1.text floatValue]+[_Field2.text floatValue];
        [_Field3.text setFloatValue:result];
    }
    but i got an error

    with
    Code:
    [_Field3.text setFloatValue:result];
    no visible @interface for NSString declares the selector 'setFloatValue:'
     
  4. DannyBres macrumors 65816

    DannyBres

    Joined:
    Oct 30, 2007
    Location:
    UK
    #4
    UITextField does not have the selector 'setFloatValue:' you want to use something like:

    Code:
    [_Field3 setText:[NSString stringWithFormat@"%d", result]];
    
    or

    Code:
    [_Field3.text = [NSString stringWithFormat@"%d", result]];
    
    I typed this in here, I do not have xCode open right now, maybe some typos in the syntax.
     
  5. abcdefg12345 thread starter macrumors regular

    abcdefg12345

    Joined:
    Jul 10, 2013
    #5
    Code:
        _Field3.text =[NSString stringWithFormat:@"%f", result];
    
    worked for me
     
  6. DannyBres macrumors 65816

    DannyBres

    Joined:
    Oct 30, 2007
    Location:
    UK
    #6
    Haha yeah thats the one! obviously don't need the [] in my second suggestion. I was typing fast with no code completion. Did I help?
     
  7. abcdefg12345 thread starter macrumors regular

    abcdefg12345

    Joined:
    Jul 10, 2013
    #7
    yes u did help i had just had to play with your code a bit to get my answer
    thanks
     

Share This Page