Skip to main content
gamedev.net
🔒 Locked

Needs some help Objective C

Started by Gwazi Jan 27, 2010 at 12:39 AM 3 replies 1.1k views
Original Post
Gwazi
Gwazi
I am reading Stephan K. book "Programming in Objective-C" and I am stuck on a exercise question. This is actually only the second chapter of this book but I can not find out what I am doing wrong. (straight from the book) The exercise calls for defining a class called XYPoint that will hold a Cartesian coordinate (x,y), where x and y are integers. Define methods to individually set the x and y coordinates of a point and retrieve their values. Write and Objective-C program to implement your new class and test it. Heres the code, I used his work for most of my reference. //Program to access instance variales - cont'd #import //----Interface Section---- @interface XYPoint: NSObject { int xAxis; int yAxis; } -(void) print; -(void) setxAxis: (int) x; -(void) setyAxis: (int) y; -(int) xAxis; -(int) yAxis; @end //----Implementation Section---- @implementation XYPoint -(void) print { NSLog (@"%i,%i", xAxis, yAxis); } -(void) setxAxis: (int) x { xAxis = x; } -(void) setyAxis: (int) y { yAxis = y; } -(int) xAxis { return xAxis; } -(int) yAxis { return yAxis; } @end //----Program Section---- int main (int argc, char *argv[]) { NSAutoreleasePool * pool = [ [NSAutoreleasePool alloc] init]; XYPoint *myXYPoint = [[XYPoint alloc] init]; [myXYPoint setxAxis: 1]; [myXYPoint setyAxis: 3]; NSLog (@"The Point Lies at (%i,%i)", [myXYPoint xAxis], [myXYPoint yAxis]); [myXYPoint release]; [pool drain]; return 0; } Any ideas? I am sure you guys will see it A.S.A.P.
RobG
RobG
What is the problem you are having?

If I compile that code and run it I get "The Point Lies at (1,3)" printed in the console, which seems to be exactly what the program should be doing?
Gwazi
Gwazi
I am writing in Xcode and there was a blue arrow. It must be a start here arrow or somthing? Well i moved that back up and it ran. So yeah no problems, go me.
Gwazi
Gwazi
Go Google.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.