Hello,
I am currently quite new to Objective C and Xcode.
I am trying to write a simple code for an applicaiton, that generates a random string of text (a fact) from an array.
I was able to do this in Javascript, but not in Xcode.
I then looked at an If function technique from this code, but I am now stuck on why it doesn't work.
RUFacts.h
#import <Cocoa/Cocoa.h>
@interface RUFacts : NSObject {
IBOutlet textField;
}
- (IBAction)reset
id)sender;
- (IBAction)set5
id)sender;
@end
RUFacts.m
#import "RUFacts.h"
@implementation RUFacts
- (IBAction)reset
id)sender {
[textField setIntValue:0];
}
- (IBAction)setTo5
id)sender {
int random_num;
random_num = (random() % 10) + 1;
[textField setIntValue:random_num];
if random_num = 1
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
else
}
@end
Any feedback, comments or suggestions would be greatly appreciated.
Do you have any ideas of how I could do what I am trying to achieve?
I am currently quite new to Objective C and Xcode.
I am trying to write a simple code for an applicaiton, that generates a random string of text (a fact) from an array.
I was able to do this in Javascript, but not in Xcode.
I then looked at an If function technique from this code, but I am now stuck on why it doesn't work.
RUFacts.h
#import <Cocoa/Cocoa.h>
@interface RUFacts : NSObject {
IBOutlet textField;
}
- (IBAction)reset
- (IBAction)set5
@end
RUFacts.m
#import "RUFacts.h"
@implementation RUFacts
- (IBAction)reset
[textField setIntValue:0];
}
- (IBAction)setTo5
int random_num;
random_num = (random() % 10) + 1;
[textField setIntValue:random_num];
if random_num = 1
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
if random_num = 2
[textField setStringValue:"Hello"];
else
}
@end
Any feedback, comments or suggestions would be greatly appreciated.
Do you have any ideas of how I could do what I am trying to achieve?