Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 10, 2018, 03:42:48 PM *
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: Ch. 3 Exercise 7  (Read 5952 times)
jdlace
Newbie
*
Posts: 4


Email
« on: March 06, 2013, 07:17:02 PM »

Hi everyone.  Very new programmer here.  Finally got through chapter 3 and tried to code my own XY coordinate program as directed. 

Here's my code for #7


#import <Foundation/Foundation.h>

// --- @INTERFACE SECTION ---

@interface XYPoint: NSObject

-(void) print;
-(void) setXcoordinate: (int) x;
-(void) setYcoordinate: (int) y;
-(int) xcoordinate;
-(int) ycoordinate;

@end

//--- @IMPLEMENTATION SECTION ---

@implementation XYPoint

{
    int xcoordinate;
    int ycoordinate;
}

-(void) print

{
    NSLog (@"%i/%i", xcoordinate, ycoordinate);
   
}

-(void) setXcoordinate: (int) x;
{
    xcoordinate = x;
   
}

-(void) setYcoordinate: (int) y;
{
    ycoordinate = y;
   
}

-(int) xcoordinate

{
   
   
    return xcoordinate;
}

-(int) ycoordinate

{
    return ycoordinate;
   
}
@end

//---PROGRAM SECTION---


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

    @autoreleasepool {
       
        XYPoint *myCoordinate = [[XYPoint alloc] init];
       
   
        //Set the coordinate
       
        [myCoordinate setXcoordinate: 1];
        [myCoordinate setYcoordinate: 3];
   
       
        //Display the point
   
        NSLog (@"The value of the XY coordinate is %i, %i",
       
        [myCoordinate xcoordinate], [myCoordinate ycoordinate]);
       
    }
   
    return 0;
}


I don't get any red stop signs indicating a fatal error; the build succeeded.  However, I do get a green bar across the last return line (I previously got it on the setYcoordinate line, but it disappeared after a few curious clicks) which read "Thread 1: breakpoint 1.1"  I also got ome spool symbols in the Navigator area. 

Can anyone tell me if there's an error in my code and/or why that "Thread 1" message appeared? 

Many, many thanks. 

J.


Logged
afterDark
Global Moderator
Full Member
*****
Posts: 131


« Reply #1 on: March 08, 2013, 04:50:00 AM »

Your program is still running when the stop button (top left corner of XCode) is not greyed out. If your program for one reason or another cannot continue till the end, the stop button is still clickable.

Now sometimes a program is stopped by XCode because there was some kind of problem. You will then receive a message, just like the one you got. The thick green bar indicates the location of trouble, the message explains a bit about the problem. Mostly these messages are somewhat cryptic I'm afraid.

Your 'problems' is, as the message says, a breakpoint. Now breakpoints are markers that you can put alongside your code, to indicate that you want the execution of the program to pause as soon as you reach that point. Maybe you want to see what the value of all the variables is once the program gets there, for instance. It is one of the tools to find your mistakes.

Apparantly you have set a breakpoint in your code, maybe by accident. Breakpoints are set in a small colums directly left from your code, a thick blue arrow. If you like, you can just drag the arrow out of the column and it will disappear with a small cloud. If you want an arrow somewhere, just click in that column.

I'd recommend you experiment a bit with that! Hope this solves your problem.

Another tip: when you post code here, it is very nice to surround it with special markers. Read about it here http://classroomm.com/objective-c/index.php?topic=7135.0 It becomes easier to read, and easier to talk about.

Hope to hear a lot more from you on these forums!
Logged

I am just an amateur with Objective-C, don't let the moderator label fool you. Working my way through the book slowly.
jdlace
Newbie
*
Posts: 4


Email
« Reply #2 on: March 08, 2013, 04:58:19 AM »

afterDark.  Thank You! These forums are great. 

cheers,

J.
Logged
JeroenJK
Newbie
*
Posts: 40



« Reply #3 on: March 11, 2013, 11:57:05 AM »

Nice program! That's what you're gonna do in Chapter 8 (but then with an object).

Good luck with the book!
Logged

Just started learning Objective-C (fourth edition), so don't expect too much from me. Wink
BrungoJames
Newbie
*
Posts: 1



Email
« Reply #4 on: September 18, 2013, 11:16:56 PM »

Hi everyone.  Very new programmer here.  Finally got through chapter 3 and tried to code my own XY coordinate program as directed. 

Here's my code for #7


#import <Foundation/Foundation.h>

// --- @INTERFACE SECTION ---

@interface XYPoint: NSObject

-(void) print;
-(void) setXcoordinate: (int) x;
-(void) setYcoordinate: (int) y;
-(int) xcoordinate;
-(int) ycoordinate;

@end

//--- @IMPLEMENTATION SECTION ---

@implementation XYPoint

{
    int xcoordinate;
    int ycoordinate;
}

-(void) print

{
    NSLog (@"%i/%i", xcoordinate, ycoordinate);
   
}

-(void) setXcoordinate: (int) x;
{
    xcoordinate = x;
   
}

-(void) setYcoordinate: (int) y;
{
    ycoordinate = y;
   
}

-(int) xcoordinate

{
   
   
    return xcoordinate;
}

-(int) ycoordinate

{
    return ycoordinate;
   
}
@end

//---PROGRAM SECTION---


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

    @autoreleasepool {
       
        XYPoint *myCoordinate = [[XYPoint alloc] init];
       
   
        //Set the coordinate
       
        [myCoordinate setXcoordinate: 1];
        [myCoordinate setYcoordinate: 3];
   
       
        //Display the point
   
        NSLog (@"The value of the XY coordinate is %i, %i",
       
        [myCoordinate xcoordinate], [myCoordinate ycoordinate]);
       
    }
   
    return 0;
}


I don't get any red stop signs indicating a fatal error; the build succeeded.  However, I do get a green bar across the last return line (I previously got it on the setYcoordinate line, but it disappeared after a few curious clicks) which read "Thread 1: breakpoint 1.1"  I also got ome spool symbols in the Navigator area. 

Can anyone tell me if there's an error in my code and/or why that "Thread 1" message appeared? 

Many, many thanks. 

J.




My friend in programming after whatever line there is a green signal means there is some error so in whatever line you got green signal check that line coding and I think then your problem will be solved and you can execute your program.
Logged
mitchb
Full Member
***
Posts: 155


« Reply #5 on: September 18, 2013, 11:32:09 PM »

You have a breakpoint set. Look for a large blue arrow to the left of your code, grab that arrow and drag it to the left and let go, it will disappear in a puff of smoke. Run your program again. You should also test your print method.

[myCoordinate print];

Mitch
Logged

If you give a man a program, you will frustrate him for a day;
If you teach him how to program, you will frustrate him for a lifetime;
     - Anonymous
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.