Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Game with Sprite Kit Physics and Collision Contact Detection using SKPhysicsContactDelegate

Shaun Kelly
Shaun Kelly
5,648 Points

Type Casting!?

Can somebody please explain what type casting is?

ProjectileNode *projectile = (ProjectileNode*) firstBody.node;
                               //^^^
Russell Warwick
Russell Warwick
1,601 Points

Okay so im not an expert by any means but basically it is away of changing the type of something for your example because ProjectileNode is of type SKSpriteNode but you assigning it to an SKNode so it just allows you to change it.<p></p> Here is an example using the value of a integer for the value of a float. <p>``` int x=6;

float y =(int)x;

NSLog(@"Float y:%f",y); </p>

  So this will print out    "Float y:6.0000000" 

Pretty easy when you get your head around it :)

2 Answers

Shaun Kelly
Shaun Kelly
5,648 Points

Is that Objective-C

Shaun Kelly
Shaun Kelly
5,648 Points

not really haha because isn't the float already an int ? or I must be getting mixed up with something else