I am completely new to Objective-C. I have written a simple SingleView Tic Tac Toe Application application for learning purposes. While writing the app, I've tried to be as much sound as I could.  Since this is my first shot, I think it can be improved a lot.Please tell me what you think about it and what you see I made wrong so I can avoid those mistakes the next time.Is there code redundancy I don't see?  Is everything declared and implemented at its right place?I will gladly provide more information about the app if needed. Just tell me!The board has this structure:slot1 | slot2 | slot3---------------------slot4 | slot5 | slot6---------------------slot7 | slot8 | slot9This is the file main.m: (This was auto generated by Xcode.)#import <UIKit/UIKit.h>#import tttAppDelegate.hint main(int argc, char *argv[]){    @autoreleasepool {        return UIApplicationMain(argc, argv, nil, NSStringFromClass([tttAppDelegate class]));    }}This is the file ViewController.h:#import <UIKit/UIKit.h>@interface tttViewController : UIViewController@property (nonatomic, retain) UIImage *circle;@property (nonatomic, retain) UIImage *cross;@property (nonatomic, retain) UIImage *imageToPlace;@property (weak, nonatomic) IBOutlet UIImageView *board;@property (weak, nonatomic) IBOutlet UIImageView *slot1;@property (weak, nonatomic) IBOutlet UIImageView *slot2;@property (weak, nonatomic) IBOutlet UIImageView *slot3;@property (weak, nonatomic) IBOutlet UIImageView *slot4;@property (weak, nonatomic) IBOutlet UIImageView *slot5;@property (weak, nonatomic) IBOutlet UIImageView *slot6;@property (weak, nonatomic) IBOutlet UIImageView *slot7;@property (weak, nonatomic) IBOutlet UIImageView *slot8;@property (weak, nonatomic) IBOutlet UIImageView *slot9;@property (weak, nonatomic) IBOutlet UILabel *msg;@property (nonatomic, retain) UIAlertView *myAlertView;@property (nonatomic, readwrite) NSInteger player;@property (nonatomic, readwrite) NSInteger round;/** * Resets the game by clearing the board and setting the variable `player` to 1. */- (IBAction)resetButton:(id)sender;/** * Determines the status of the game. If all 9 fields were used or if there are * 3 circles or 3 crosses in a row it invokes an alertview which tells who won * thegame. */- (void)gameStatus;/** * Changes players and updates the label which displays the player name. * Places the cross or the circle on the board. */- (void)switchPlayers;/** * Checks if somone has won and returns true. */- (BOOL)somebodyWon;@endAnd this is ViewController.m:#import tttViewController.h@implementation tttViewController// @synthesize means create getter and setter methods.@synthesize slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9;@synthesize circle;@synthesize cross;@synthesize imageToPlace;@synthesize board;@synthesize msg;@synthesize myAlertView;@synthesize player;@synthesize round;- (void)viewDidLoad {    circle = [UIImage imageNamed:@circle.png];    cross = [UIImage imageNamed:@cross.png];    player = 1;    round = 0;    msg.text = @Player 1: Put a \Cross\ on the field!;    [super viewDidLoad]; // Autogenerated.}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    if (player == 1) {        imageToPlace = cross;    } else if (player == 2) {        imageToPlace = circle;    }    UITouch *touch = [[event allTouches] anyObject];    [self slot:slot1 wasTouched:touch];    [self slot:slot2 wasTouched:touch];    [self slot:slot3 wasTouched:touch];    [self slot:slot4 wasTouched:touch];    [self slot:slot5 wasTouched:touch];    [self slot:slot6 wasTouched:touch];    [self slot:slot7 wasTouched:touch];    [self slot:slot8 wasTouched:touch];    [self slot:slot9 wasTouched:touch];}-(void)slot:(UIImageView *)slot wasTouched:(UITouch *)touch {    if ((slot.image == NULL) &&        CGRectContainsPoint([slot frame], [touch locationInView:self.view])) {        slot.image = imageToPlace;        round++;        [self gameStatus];    } }-(void)gameStatus{    BOOL win = [self somebodyWon];    if (round == 9 || win) {        myAlertView = nil;        NSString *result = nil;        if (round == 9 && !win) {            result = @Draw!;        }        else if (round <= 9 && win){            if(player == 1){                result = @Player 1 won!;            }            else if(player == 2){                result = @Player 2 won!;            }        }        else {            result = @Sorry! Something went wrong when determining win/draw situation.;        }        myAlertView = [[UIAlertView alloc] initWithTitle:@Result: message:result delegate:self cancelButtonTitle:@Ok! otherButtonTitles:nil, nil];        [myAlertView show];        [self resetBoard];    } else {        [self switchPlayers];    }}-(BOOL)somebodyWon{    /**     * Check for win in the leftmost column and in the topmost row.     */    if(slot1.image != NULL) {        if (((slot1.image == slot2.image) && (slot1.image == slot3.image)) ||            ((slot1.image == slot4.image) && (slot1.image == slot7.image))) {            return YES;        }    }    /**     * Check for wins that goe through the middle of the board.     */    if(slot5.image != NULL) {        if (((slot5.image == slot4.image) && (slot5.image == slot6.image)) ||            ((slot5.image == slot2.image) && (slot5.image == slot8.image)) ||            ((slot5.image == slot1.image) && (slot5.image == slot9.image)) ||            ((slot5.image == slot3.image) && (slot5.image == slot7.image))) {            return YES;        }    }        /**     * Check for win in the rightmost column and in the lowest row.     */    if(slot9.image != NULL) {        if (((slot9.image == slot6.image) && (slot9.image == slot3.image)) ||            ((slot9.image == slot8.image) && (slot9.image == slot7.image))) {            return YES;        }    }    return NO;}- (IBAction)resetButton:(id)sender {    [self resetBoard];}//-(IBAction)buttonReset{//    [self resetBoard];//}-(void)resetBoard{    slot1.image = NULL;    slot2.image = NULL;    slot3.image = NULL;    slot4.image = NULL;    slot5.image = NULL;    slot6.image = NULL;    slot7.image = NULL;    slot8.image = NULL;    slot9.image = NULL;    player = 1;    msg.text = @Player 1: Put a \Cross\ on the field;    round = 0;}-(void)switchPlayers{    if (player == 1){        player = 2;        msg.text = @Player 2: Put a \Circle\ on the field;    } else {        player = 1;        msg.text = @Player 1: Put a \Cross\ on the field;    }}- (void)viewDidUnload{    [super viewDidUnload];    // Release any retained subviews of the main view.}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}@end
Review of Tic Tac Toe game in Objective-C
beginner;objective c;game
#import tttViewController.h@implementation tttViewController// @synthesize means create getter and setter methods.I'd avoid commenting to explain language features. Assume your reader knows the language.@synthesize slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9;Slot has a particular meaning in objective-c, so I'd pick another name to use here@synthesize circle;@synthesize cross;@synthesize imageToPlace;@synthesize board;@synthesize msg;@synthesize myAlertView;@synthesize player;@synthesize round;- (void)viewDidLoad {    circle = [UIImage imageNamed:@circle.png];    cross = [UIImage imageNamed:@cross.png];I'd put these in an array, then you can avoid using if to pick them    player = 1;    round = 0;    msg.text = @Player 1: Put a \Cross\ on the field!;    [super viewDidLoad]; // Autogenerated.}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    if (player == 1) {        imageToPlace = cross;    } else if (player == 2) {        imageToPlace = circle;    }Don't use object variables to pass data. Pass it as function arguments    UITouch *touch = [[event allTouches] anyObject];    [self slot:slot1 wasTouched:touch];    [self slot:slot2 wasTouched:touch];    [self slot:slot3 wasTouched:touch];    [self slot:slot4 wasTouched:touch];    [self slot:slot5 wasTouched:touch];    [self slot:slot6 wasTouched:touch];    [self slot:slot7 wasTouched:touch];    [self slot:slot8 wasTouched:touch];    [self slot:slot9 wasTouched:touch];Instead of doing this, create a slots array and push all the slots in it. Then you can use a loop for things like this}-(void)slot:(UIImageView *)slot wasTouched:(UITouch *)touch {This name is somewhat confusing because it implies the slot was touched. However, since you call it for all the touches that may not be true    if ((slot.image == NULL) &&        CGRectContainsPoint([slot frame], [touch locationInView:self.view])) {        slot.image = imageToPlace;        round++;        [self gameStatus];    } }-(void)gameStatus{The name gameStatus implies that it returns the game status. But this is really more of a updateGameStatus    BOOL win = [self somebodyWon];    if (round == 9 || win) {        myAlertView = nil;Why isn't this a local variable?        NSString *result = nil;Result isn't a very clear name, text would be better        if (round == 9 && !win) {All you really want to do is handle win or not win. Your logic here is way complicated. Just do if(win)            result = @Draw!;        }        else if (round <= 9 && win){            if(player == 1){                result = @Player 1 won!;            }            else if(player == 2){                result = @Player 2 won!;            }        }        else {            result = @Sorry! Something went wrong when determining win/draw situation.;        }Cleanup your logic so it's clear this'll never happen and then get rid of this silly case.        myAlertView = [[UIAlertView alloc] initWithTitle:@Result: message:result delegate:self cancelButtonTitle:@Ok! otherButtonTitles:nil, nil];Do you really need the delegate here?        [myAlertView show];        [self resetBoard];    } else {        [self switchPlayers];    }}-(BOOL)somebodyWon{The name is ambigious. It could check is somebody won or it could be called if somebody won    /**     * Check for win in the leftmost column and in the topmost row.     */    if(slot1.image != NULL) {        if (((slot1.image == slot2.image) && (slot1.image == slot3.image)) ||            ((slot1.image == slot4.image) && (slot1.image == slot7.image))) {            return YES;        }    }Slightly confusing way to do this. If you put the slots in an array, you should be able to simplify this logic. Also, generally prefer to store game state in normal variables, not as whether images are set on ui controls.    /**     * Check for wins that goe through the middle of the board.     */    if(slot5.image != NULL) {        if (((slot5.image == slot4.image) && (slot5.image == slot6.image)) ||            ((slot5.image == slot2.image) && (slot5.image == slot8.image)) ||            ((slot5.image == slot1.image) && (slot5.image == slot9.image)) ||            ((slot5.image == slot3.image) && (slot5.image == slot7.image))) {            return YES;        }    }        /**     * Check for win in the rightmost column and in the lowest row.     */    if(slot9.image != NULL) {        if (((slot9.image == slot6.image) && (slot9.image == slot3.image)) ||            ((slot9.image == slot8.image) && (slot9.image == slot7.image))) {            return YES;        }    }    return NO;Consider returning a number of options: Stalement, X-Wins, Y-Wins, GameContinues. I think that'll make the code clearer}- (IBAction)resetButton:(id)sender {    [self resetBoard];}//-(IBAction)buttonReset{//    [self resetBoard];//}Delete dead code, don't comment it out-(void)resetBoard{    slot1.image = NULL;    slot2.image = NULL;    slot3.image = NULL;    slot4.image = NULL;    slot5.image = NULL;    slot6.image = NULL;    slot7.image = NULL;    slot8.image = NULL;    slot9.image = NULL;    player = 1;    msg.text = @Player 1: Put a \Cross\ on the field;    round = 0;Message is duplicated, put it in a constant, or find a way to use switchPlayers}-(void)switchPlayers{    if (player == 1){        player = 2;        msg.text = @Player 2: Put a \Circle\ on the field;    } else {        player = 1;        msg.text = @Player 1: Put a \Cross\ on the field;    }}- (void)viewDidUnload{    [super viewDidUnload];    // Release any retained subviews of the main view.}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}@end