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

iOS Xcode errors - Help -

Aephix

macrumors newbie
Original poster
Jul 4, 2015
6
0
Hello guys I'm pretty new to Xcode and programming for iOS in general, however I've recently written some code for my application and I am having 3 errors which are:

In the ViewController.m section.

The issues are:

1st Error

Semantic Issue - Undeclared selector 'missleMovement'

Code:
missleMovementTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector (missleMovement) userInfo:nil repeats:YES];


2nd Error

ARC Semantic Issue - No visible @interface for 'ViewController' declares the selector 'gameOver'

Code:
[self gameOver];


3rd Error

Semantic Issue - Use of undeclared identifier 'missleMovement'

Code:
-(void)missleMovement



These are the 3 parts of my whole code that is giving issues. I'm not sure why I'm a newbie if you can understand any of the errors and give advice I would appreciate that.

If you require more info in regards to the application I can freely explain to give a better understanding.



FULL CODE

Code:
#import "ViewController.h"

@interface ViewController ()

@end

int score;
int lives;
int enemyAttackOccurence;
int enemyPosition;
int randomSpeed;
float speedOfEnemy;




@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)viewDidAppear:(BOOL)animated {
  
    // Images that are to be hidden
    friendlyShip.hidden = YES;
    enemyShip.hidden = YES;
    motherShip.hidden = YES;
    missle.hidden = YES;
  
    // Labels to be hidden
    scoreLabel.hidden = YES;
    livesLabel.hidden = YES;
  
    // Set score and lives remaining
    score = 0;
    lives = 3;
  
    // Strings
    scoreString = [NSString stringWithFormat:@"SCORE; 0"];
    liveString = [NSString stringWithFormat:@"LIVES; 3"];
  
    // Initials Label text
    scoreLabel.text = scoreString;
    livesLabel.text = liveString;
  
    // Starting position of images
    friendlyShip.center = CGPointMake(140, 400);
    enemyShip.center = CGPointMake(140, -40);
    missle.center = CGPointMake(friendlyShip.center.x, friendlyShip.center.y);
  
  
    motherShip.layer.cornerRadius = 50;
  
  
  
}

-(IBAction)startGame:(id)sender {
  
    // Hide start button
    startButton.hidden = YES;
  
    // Show images
    friendlyShip.hidden = NO;
    enemyShip.hidden = NO;
    motherShip.hidden = NO;
  
    // Display labels
    scoreLabel.hidden = NO;
    livesLabel.hidden = NO;
  
  
  
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  
  
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  
    touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
  
    friendlyShip.center = CGPointMake(point.x, friendlyShip.center.y);
  
  
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  
    [missleMovementTimer invalidate];
    missle.hidden = NO;
    missle.center = CGPointMake(friendlyShip.center.x, friendlyShip.center.y);
  
    missleMovementTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(missleMovement) userInfo:nil repeats:YES];
  
  
}

-(void)positionEnemy {
  
    // Random enemy position
    enemyPosition = arc4random() %249;
    enemyPosition = enemyPosition + 20;
  
    // Set enemy Image location
    enemyShip.center = CGPointMake(enemyPosition, -40);
  
    // Set enemy speed
  
    randomSpeed = arc4random() % 3;
    switch (randomSpeed) {
        case 0:
            speedOfEnemy = 0.03;
            break;
        case 1:
            speedOfEnemy = 0.02;
            break;
        case 2:
            speedOfEnemy = 0.01;
          
        default:
            break;
    }
  
    enemyAttackOccurence = arc4random() % 5;
  
    [self performSelector:@selector(enemyMovementTimerMethod) withObject:nil afterDelay:enemyAttackOccurence];
  
}

-(void)enemyMovementTimerMethod {
  
    enemyMovementTimer = [NSTimer scheduledTimerWithTimeInterval:speedOfEnemy target:self selector:@selector(enemyMovement) userInfo:nil repeats:YES];
  
}

-(void)enemyMovement {
  
    enemyShip.center = CGPointMake(enemyShip.center.x, enemyShip.center.y + 2);
  
    if (CGRectIntersectsRect(enemyShip.frame, motherShip.frame)) {
      
        lives = lives - 1;
        liveString = [NSString stringWithFormat:@"LIVES: %i", lives];
        livesLabel.text = liveString;
      
        // Stop enemy moving
      
        [enemyMovementTimer invalidate];
      
        if ( lives > 0) {
            [self positionEnemy];
        }
      
        if ( lives == 0) {
            [self gameOver];
        }
      
      
      
    }

-(void)missileMovement {
  
    missile.hidden = NO;
    missile.center = CGPointMake(missile.center.x, missle.center.y - 2);
  
    if (CGRectIntersectsRect(missile.frame, enemyShip.frame)) {
        score = score + 5;
        scoreString = [NSSTring stringWithFormat:@"SCORE: %i", score];
        scoreLabel.text = scoreString;
      
        // Stop missle
        [missileMovementTimer invalidate];
      
        // Position missle to be central to friendly ship
        missile.center = CGPOintMake(friendlyShip.center.x, friendlyShip.center.y);
        missile.hidden = YES;
      
        // Stop enemy movement
        [enemyMovementTimer invalidate];
        [self positionEnemy];
      
    }
  
  
}
-(void)gameOver {
  
    [enemyMovementTimer invalidate];
    [missleMovementTimer invalidate];
    [self performSelector:@selector(replayGame) withObject:nil afterDelay:3];
  
}

-(void)replayGame {
  
    // Images that are to be hidden
    friendlyShip.hidden = YES;
    enemyShip.hidden = YES;
    motherShip.hidden = YES;
    missle.hidden = YES;
  
    // Labels to be hidden
    scoreLabel.hidden = YES;
    livesLabel.hidden = YES;
  
    // Set score and lives remaining
    score = 0;
    lives = 3;
  
    // Strings
    scoreString = [NSString stringWithFormat:@"SCORE; 0"];
    liveString = [NSString stringWithFormat:@"LIVES; 0"];
  
    // Initials Label text
    scoreLabel.text = scoreString;
    livesLabel.text = liveString;
  
    // Starting position of images
    friendlyShip.center = CGPointMake(140, 400);
    enemyShip.center = CGPointMake(140, -40);
    missle.center = CGPointMake(friendlyShip.center.x, friendlyShip.center.y);

    motherShip.layer.cornerRadius = 50;
  
}

    @end}
@end


ViewController.h

Code:
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
   
    IBOutlet UIImageView *friendlyShip;
    IBOutlet UIImageView *enemyShip;
    IBOutlet UIImageView *motherShip;
    IBOutlet UIImageView *missile;
   
    IBOutlet UILabel *livesLabel;
    IBOutlet UILabel *scoreLabel;
   
    IBOutlet UIButton *startButton;
   
    UITouch *touch;
   
    NSString *liveString;
    NSString *scoreString;
   
    NSTimer *enemyMovementTimer;
    NSTimer *missileMovementTimer;
   
   
   
   
}

-(IBAction)startGame:(id)sender;

@end
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
8,875
5,321
vertical
Pleas post your code for every method declaration. Maybe you jst speled somthing wrng.

What you posted shows missleMovement. Note the spelling carefully. Should there be another 'i' in the word "missle", i.e. should it be "missile"? No one here can say for sure, because you didn't post enough code.
 
Comment

Aephix

macrumors newbie
Original poster
Jul 4, 2015
6
0
Pleas post your code for every method declaration. Maybe you jst speled somthing wrng.

What you posted shows missleMovement. Note the spelling carefully. Should there be another 'i' in the word "missle", i.e. should it be "missile"? No one here can say for sure, because you didn't post enough code.


Even with that being corrected I'm still receiving that error however I will update the thread with the full code.

Thank you!
 
Comment

larswik

macrumors 68000
Sep 8, 2006
1,552
11
Code:
        scoreString = [NSSTring stringWithFormat:@"SCORE: %i", score];
That line of code has a error in it. I saw one more in that same method. Like Chown33 said look over the way you spelled everything. You should be getting a Red Error mark on that line, and also one more line that I saw in this same method that had a typo.
 
Comment

Aephix

macrumors newbie
Original poster
Jul 4, 2015
6
0
Code:
        scoreString = [NSSTring stringWithFormat:@"SCORE: %i", score];
That line of code has a error in it. I saw one more in that same method. Like Chown33 said look over the way you spelled everything. You should be getting a Red Error mark on that line, and also one more line that I saw in this same method that had a typo.


Well even fixing small mistakes like that which has not caused me any errors does not fix the stated errors.

I'm still trying to figure it out while I'm seeking answers. But I have not been able to solve it at the moment.
 
Comment

Aephix

macrumors newbie
Original poster
Jul 4, 2015
6
0
Thanks for going through my code I have literally fixed all of the spelling mistakes that I've found and I have searched for misspelt words also I can guarantee that my code is 100% accurate on spelling here is an image below of the error I am getting it may give you a better idea of what's going on.

Thanks a lot for the help.
 

Attachments

  • Screen Shot 2015-07-05 at 00.37.33.png
    Screen Shot 2015-07-05 at 00.37.33.png
    24.3 KB · Views: 76
Comment

chown33

Moderator
Staff member
Aug 9, 2009
8,875
5,321
vertical
1. Please post the file "ViewController.h". The posted code is importing this file, but I don't see the file itself.

I can tell some things are missing from the posted code, because there are no declarations for variables like friendlyShip, enemyShip, motherShip. I'm guessing those are declared in ViewController.h, but it's just a guess.


2. You have mismatched {}'s, and probably an extraneous @end. Here's the tail end of your posted code:
Code:
    @end}
@end
Double-click the } that immediately follows the @end. It should select everything between the matching { and the } you double-clicked. Now without deselecting anything, scroll up to where the selection begins. You should find it's here:
Code:
-(void)enemyMovement {
So one problem is there's an @end inside the method enemyMovement. This is wrong.

Another problem is that the enemyMovement method contains sub-methods (not allowed in Obj-C), apparently because you neglected to put a } at the proper place. The proper place is probably before this:
Code:
-(void)missileMovement {


3. If you're working from a tutorial or book, exactly which one? Post its URL or the book's title, author, and what page your code is from.

Knowing what you're working from and with is important context for us to understand the code you posted.


Info on Xcode bracket matching:
https://developer.apple.com/library...ditor/chapters/MatchingPairsofDelimiters.html
 
Last edited:
Comment

Aephix

macrumors newbie
Original poster
Jul 4, 2015
6
0
1. Please post the file "ViewController.h". The posted code is importing this file, but I don't see the file itself.

I can tell some things are missing from the posted code, because there are no declarations for variables like friendlyShip, enemyShip, motherShip. I'm guessing those are declared in ViewController.h, but it's just a guess.


2. You have mismatched {}'s, and probably an extraneous @end. Here's the tail end of your posted code:
Code:
    @end}
@end
Double-click the } that immediately follows the @end. It should select everything between the matching { and the } you double-clicked. Now without deselecting anything, scroll up to where the selection begins. You should find it's here:
Code:
-(void)enemyMovement {
So one problem is there's an @end inside the method enemyMovement. This is wrong.

Another problem is that the enemyMovement method contains sub-methods (not allowed in Obj-C), apparently because you neglected to put a } at the proper place. The proper place is probably before this:
Code:
-(void)missileMovement {


3. If you're working from a tutorial or book, exactly which one? Post its URL or the book's title, author, and what page your code is from.

Knowing what you're working from and with is important context for us to understand the code you posted.


Info on Xcode bracket matching:
https://developer.apple.com/library...ditor/chapters/MatchingPairsofDelimiters.html


Thank you for the quick replies I have added the ViewController.h file. The suggestions you made I will implement them and try to follow up on them and see if they fix the issues once I have done that I'll reply with what happened.

Thank you once more!
 
Comment

Aephix

macrumors newbie
Original poster
Jul 4, 2015
6
0
1. Please post the file "ViewController.h". The posted code is importing this file, but I don't see the file itself.

I can tell some things are missing from the posted code, because there are no declarations for variables like friendlyShip, enemyShip, motherShip. I'm guessing those are declared in ViewController.h, but it's just a guess.


2. You have mismatched {}'s, and probably an extraneous @end. Here's the tail end of your posted code:
Code:
    @end}
@end
Double-click the } that immediately follows the @end. It should select everything between the matching { and the } you double-clicked. Now without deselecting anything, scroll up to where the selection begins. You should find it's here:
Code:
-(void)enemyMovement {
So one problem is there's an @end inside the method enemyMovement. This is wrong.

Another problem is that the enemyMovement method contains sub-methods (not allowed in Obj-C), apparently because you neglected to put a } at the proper place. The proper place is probably before this:
Code:
-(void)missileMovement {


3. If you're working from a tutorial or book, exactly which one? Post its URL or the book's title, author, and what page your code is from.

Knowing what you're working from and with is important context for us to understand the code you posted.


Info on Xcode bracket matching:
https://developer.apple.com/library...ditor/chapters/MatchingPairsofDelimiters.html







You're a legend I've officially fixed my code with no errors.

Thank you very much! I hope if in the future I have some questions etc you'll be fine if I maybe contact you in regards to it?

If not once again thanks for the help sir!
 
Comment

chown33

Moderator
Staff member
Aug 9, 2009
8,875
5,321
vertical
You're a legend I've officially fixed my code with no errors.

Thank you very much! I hope if in the future I have some questions etc you'll be fine if I maybe contact you in regards to it?

If not once again thanks for the help sir!
You're quite welcome. Glad it solved the problem.

I only answer public posted questions. If you have a question in the future, start a thread here. That way a lot more people can look at it and attempt to answer it.
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.