Ben Wilson
Ben Wilson

Reputation: 31

App Crashes when touched

when i build the app i get a warning on the UITouch line saying

Incompatible Object-c initializing 'struct NSArray *', expected 'struct UITouch *'

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *myTouch = [[event allTouches] allObjects];
        player.center = [myTouch locationInView:self.view];
    }

and when i run the app it all starts fine until i click the player and then it closes down. can anyone help?

Upvotes: 2

Views: 156

Answers (3)

Swizzlr
Swizzlr

Reputation: 447

Your variable myTouch is a pointer to a UITouch object. However, if you look at the documentation, you will find that allTouches of a UIEvent returns an NSSet, and allObjects of an NSSet returns an NSArray. You are therefore trying to tell the computer that myTouch is going to get a UITouch object passed in, when it will almost certainly get an NSArray.

Like putting a square peg in a round hole.

Upvotes: 0

sergio
sergio

Reputation: 69047

Possibly you meant:

UITouch *myTouch = [[event allTouches] anyObject];

or:

UITouch *myTouch = [touches anyObject];

Upvotes: 0

Vladimir
Vladimir

Reputation: 170849

-allObjects method returns NSArray of your touches, if you want to get single object from set you need to use -anyObject method:

UITouch *myTouch = [[event allTouches] anyObject];

Upvotes: 1

Related Questions