简单的Objective-C命令行代码在终端中运行良好,在Xcode中中断

时间:2014-08-11 14:57:26

标签: objective-c xcode

我正在通过Stephen Kochan的Objective-C 中的编程工作,并且已经解决了其中一个练习,即为2D坐标值创建一个类。我的代码使用Xcode命令行工具运行良好,但是如果我尝试在Xcode中运行相同的程序,它似乎会中断。

的main.m

#import <Foundation/Foundation.h>

//--- @interface section ---
@interface Cartesian: NSObject

-(void) setCoordinateX: (int) x;
-(void) setCoordinateY: (int) y;
-(int) coordinateX;
-(int) coordinateY;
-(void) print;

@end

//--- @implementation section ---
@implementation Cartesian
{
    int coordinateX;
    int coordinateY;
}

-(void) setCoordinateX: (int) x
{
    coordinateX = x;
} // Xcode highlights this row as green (breakpoint)

-(void) setCoordinateY: (int) y
{
    coordinateY = y;
}

-(int) coordinateX
{
    return coordinateX;
}

-(int) coordinateY
{
    return coordinateY;
}

-(void) print
{
    NSLog(@"This coordinate value is (%i,%i)", coordinateX, coordinateY);
}

@end

//--- program section ---
int main(int argc, const char * argv[])
{
    @autoreleasepool {

        Cartesian *point1 = [Cartesian new];

        [point1 setCoordinateX: 3];
        [point1 setCoordinateY: 4];

        [point1 print];
        NSLog(@"To reiterate, this coordinate value is (%i,%i)", [point1 coordinateX], [point1 coordinateY]);

    }
    return 0;
}

任何人都可以帮助我理解 1.出了什么问题? 2.为什么使用Xcode命令行工具在终端中运行良好?

2 个答案:

答案 0 :(得分:0)

在某些情况下,您的代码可能会破坏Xcode,因为Xcode传递的实际编译器标志通常比在终端中只输入gcc或clang更复杂。

在这种情况下,您必须向我们提供在Xcode中抛出错误的行,以便查看可以修复的内容。

答案 1 :(得分:0)

您很可能实际上添加了手动断点

enter image description here

双击(选项点击)它并将其移除或只是将其拖放到窗外。

断点是一种告诉应用程序在达到条件(或代码行)时停止的方法。您可以使用它们来检查应用程序的状态,检查变量,逐步执行代码等。调试应用程序时最重要的事情之一。