Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

iOS Convert Mac code to iOS

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
280
86
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
 

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
280
86
:%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".

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:'
 

DannyBres

macrumors 65816
Oct 30, 2007
1,412
6
UK
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.
 

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
280
86
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.

Code:
    _Field3.text =[NSString stringWithFormat:@"%f", result];

worked for me
 

DannyBres

macrumors 65816
Oct 30, 2007
1,412
6
UK
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?
 

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
280
86
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?

yes u did help i had just had to play with your code a bit to get my answer
thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.