Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
October 19, 2017, 09:38:10 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Chapter 8.5B (2 myPoints)  (Read 1870 times)
goorange
Newbie
*
Posts: 11


« on: August 19, 2010, 07:16:53 AM »

Thought it would be interesting to test whether or not myPoint could be used multiple times and to extract a second myPoint.  Are there any issues that can arise by using myPoint this way?

Here's the main:

Code: (Objective-C)
// See Programming in Objective-C 2.0.  Chapter 8, Programs 8.2 - 

#import <Foundation/Foundation.h>
#import "Square.h"
#import "XYPoint.h"
#import "Rectangle.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    Rectangle *myRect = [[Rectangle alloc] init];
Rectangle *myRect2 = [[Rectangle alloc] init];
XYPoint *myPoint = [[XYPoint alloc] init];

[myPoint setX: 100 andY: 200];

[myRect setWidth: 5 andHeight: 8];
myRect.origin = myPoint;
NSLog(@"Origin 1 at (%i, %i)", myRect.origin.x, myRect.origin.y);

[myPoint setX: 50 andY: 50];

[myRect setWidth: 20 andHeight: 30];
myRect2.origin = myPoint;
NSLog(@"Origin 2 at (%i, %i)", myRect2.origin.x, myRect2.origin.y);

[[myRect origin] release];
[myRect release];
[myPoint release];
   
[pool drain];
    return 0;
}


Output:

[Session started at 2010-08-19 10:11:23 -0400.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May  5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 1194]
Running…
2010-08-19 10:11:23.558 prog8.2[1194:a0f] Origin 1 at (100, 200)
2010-08-19 10:11:23.561 prog8.2[1194:a0f] Origin 2 at (50, 50)


Debugger stopped.
Program exited with status value:0.
« Last Edit: August 19, 2010, 07:21:13 AM by goorange » Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #1 on: August 20, 2010, 08:51:05 PM »

I don't know which version of setOrigin: you're using here.  If you're overriding dealloc, the rectangle's origin should be released there and not in your main routine, as noted later in the chapter.  If you're not overriding dealloc you also need to include a [[myRect2 origin] release]; statement in your program.

Cheers,

Steve Koc han
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

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 ゥ 2009 classroomM.com. All rights reserved.