Amazon.com Widgets Exercise #7 questions:
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 21, 2013, 04:40:46 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 3
| | | |-+  Exercise #7 questions:
Pages: [1]   Go Down
Print
Author Topic: Exercise #7 questions:  (Read 726 times)
alexsom
Jr. Member
**
Posts: 63



Email




« on: January 13, 2012, 05:58:47 PM »

Here is exercise#7 Chapter 3, but with some ambiguities going on.
First of all, if anyone is using Xcode 4.2, like myself, and has ARC activated on it, some classes and declarations are not allowed, like NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; , or anything that needs to be released from the memory like [myObject release], as long as ARC is activated. Also, though I haven't used @autoreleasepool in my program, and surprisingly it works without it, the compiler tells me that implementation section is incomplete….why, I have no idea.
I look forward to receiving my 4th Edition soon because it's frustrating with an older version using an updated compiler.

Here is my effort having two points instead of one.


//.…………….@interface section…………..
@interface XYPoint: NSObject
{
    int coordX;
    int coordY;
}

-(void) print;
-(void) setCoordX:  (int) x;
-(void) setCoordY:  (int) y;
-(int) coordX;
-(int) coordY;

@end

//.……………@implementation section…………..  

@implementation XYPoint        

-(void) print
{
    NSLog (@ "(%i,%i)", coordX, coordY);
}
-(void) setCoordX: (int) x
{
    coordX = x;
}
-(void) setCoordY: (int) y
{
    coordY = y;
}

@end

// ……………….program section………………

int main (int argc, char *argv[])
{

XYPoint  *myXYPoint1 = [ [ XYPoint alloc] init ];
XYPoint  *myXYPoint2 = [ [ XYPoint alloc] init ];

// Set first point with coordinates (5,

[myXYPoint1 setCoordX: 5];
[myXYPoint1 setCoordY: 8];

// Set second point with coordinates (-3, -11)

[myXYPoint2 setCoordX: -3];
[myXYPoint2 setCoordY: -11];

// Display the points
    {
NSLog (@"The coordinates of the first point are:");
[myXYPoint1 print];


NSLog (@"The coordinates of the second point are:");
[myXYPoint2 print];

}
return 0;

}
Anyway, to my surprise the program was compiled successfully and in the output window it was displayed the following:
2012-01-13 18:23:33.116 exer4[3291:707] The coordinates of the first point are:
2012-01-13 18:23:33.141 exer4[3291:707] (5,8)
2012-01-13 18:23:33.142 exer4[3291:707] The coordinates of the second point are:
2012-01-13 18:23:33.143 exer4[3291:707] (-3,-11)

Please let me know if you have any idea why that happens in the implementation section, and why it works without @autoreleasepool. Thank you.
Logged
alexsom
Jr. Member
**
Posts: 63



Email




« Reply #1 on: January 13, 2012, 07:48:18 PM »

Here is with the @autoreleasepool and it's working. I still couldn't figure out why I get the message "Incomplete implementation". If anyone finds out please let me know.


//.…@interface section…………..
@interface XYPoint: NSObject
{
    int coordX;
    int coordY;
}

-(void) print;
-(void) setCoordX:  (int) x;
-(void) setCoordY:  (int) y;
-(int) coordX;
-(int) coordY;

@end

//.…@implementation section…………..

@implementation XYPoint

-(void) print
{
    NSLog (@ "(%i,%i)", coordX, coordY);
}
-(void) setCoordX: (int) x
{
    coordX = x;
}
-(void) setCoordY: (int) y
{
    coordY = y;
}

@end

// …program section………………

int main (int argc, char *argv[])
{
    @autoreleasepool
     {

       XYPoint  *myXYPoint1 = [ [ XYPoint alloc] init ];
       XYPoint  *myXYPoint2 = [ [ XYPoint alloc] init ];
       
       // Set first point with coordinates (5, Cool

       [myXYPoint1 setCoordX: 5];
       [myXYPoint1 setCoordY: 8];
       
       //Set second point with coordinates (-3,-11)
       [myXYPoint2 setCoordX: -3];
       [myXYPoint2 setCoordY: -11]; 

       // Display the point
             {
                 
             NSLog (@"The coordinates of the first point are:");
            [myXYPoint1 print];
                 
             NSLog (@"The coordinates of the second point are:");
            [myXYPoint2 print];
                 
             }
       return 0;

        }

}
Logged
alexsom
Jr. Member
**
Posts: 63



Email




« Reply #2 on: January 14, 2012, 06:51:00 PM »

I've found out today why it tells me "incomplete implementation", and that's because I didn't specify the parent class:
@implementation XYPoint: NSObject
Kudos
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.