1

In my code I am getting "missing context for method declaration" errors for both -(void) statements, and I am not able find out why.

Here is my code:

- (void)onTimer {
[self checkCollision];
bad.center = CGPointMake(bad.center.x+pos.x,bad.center.y+pos.y);
if(bad.center.x >320 || bad.center.x<0)
    pos.x = -pos.x;
if(bad.center.y >480 || bad.center.y<0)
    pos.y = -pos.y;
}

- (void) checkCollision {
if (CGRectIntersectsRect(good.frame,bad.frame)) {
    [startButton setHidden:NO];
    [timer invalidate];

    CGRect frame = [good frame];
    frame.origin.x = 132.0;
    frame.origin.y = 332.0;
    [good setFrame:frame];

    CGRect frame2 = [good frame];
    frame2.origin.x = 125.0;
    frame2.origin.y = 70.0;
    [bad setFrame:frame2]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your not fast enough!"                         message:@"Try again!" delegate:nil cancelButtonTitle:@"Dismiss"otherButtonTitles:nil];

    [alert show];
    [alert release];
}
@end
danielbeard
  • 9,120
  • 3
  • 44
  • 58
user2230366
  • 47
  • 1
  • 2
  • 1
    I hate receiving such a bashing for posting my honest questions here, i will ask somewhere else next time, sorry for the inconvenience – user2230366 Apr 02 '13 at 05:56
  • Also I urge you to follow my simple suggestion from your other question of finding some working code and comparing your own to it. You probably will find the solution, and learn something. If you try that, and still can't get it even after searching, that probably means you have a good candidate for a new question. But right now it looks like you are just announcing to the world that you don't want to do anything to help yourself which is why you are being voted down. – Carl Veazey Apr 02 '13 at 06:13
  • First of all, and probably the last of all, the @implementation MyClassName part is actually not needed, and you are wrong. I have a similar problem, and I have two .h files. One of them raises the error the OP asked. Other one does not. Something else has to be the problem. – Vladimir Despotovic Sep 18 '17 at 19:37

1 Answers1

1

Now in this case;

You dont have, @implementation <ClassName> on top.

The error "missing context for method declaration" is only due to that.

Also, you did not have matching closing }

- (void) checkCollision {
    if (CGRectIntersectsRect(good.frame,bad.frame)) {


    ...

    }//for if

}//for checkCOllision

Always check number of opening { is matched with number of closing }.

For this kind of error, Follow this easy steps :

Step 1 : Cmd+A

Step 2 : Ctrl+I

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • Yes, this is an error, but this is not the one that causes the compiler error. OP doesn't seem to have the `@implementation` keyword. –  Apr 02 '13 at 06:00
  • 1
    @H2CO3: I didn't read the question only saw the codes and found this one :p – Anoop Vaidya Apr 02 '13 at 06:03
  • i dont know what to say after @implementation for that one though – user2230366 Apr 02 '13 at 06:03
  • @AnoopVaidya Hehe. Well, at least you got the other one as well, +1. –  Apr 02 '13 at 06:06
  • @user2230366 Say "thank you" to Anoop, and write the name of the class you're implementing these methods in. –  Apr 02 '13 at 06:07
  • 1
    @H2CO3: Or in next minute you would have seen another question saying **Missing '@end' , Expected '}' and Unexpected '@' in program** – Anoop Vaidya Apr 02 '13 at 06:10
  • @AnoopVaidya Now that is pretty sure, I must admit. –  Apr 02 '13 at 06:10
  • 1
    @H2CO3: last evening I asked [Code Snippet](http://stackoverflow.com/questions/15745605/add-time-and-date-in-custom-user-code-snippet-in-xcode) Check that – Anoop Vaidya Apr 02 '13 at 06:13
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/27377/discussion-between-h2co3-and-anoop-vaidya) –  Apr 02 '13 at 06:14
  • 1
    @user2230366: go on to accept all the answers... that will mark your questions as answered and you will get some points..and also I will earn many points :) – Anoop Vaidya Apr 02 '13 at 17:26
  • @AnoopVaidya I don't have a implementation part on top and in one file, it is not raising any error. I tried making a another similar file, with the same structure and this time it raises the error. I am not sure what is the problem here, but it looks it is not (at least not ONLY) the implementation part. – Vladimir Despotovic Sep 18 '17 at 19:39
  • @VladimirDespotovic: Cant solve without seeing the code, and compiler settings. – Anoop Vaidya Sep 20 '17 at 02:42