【问题标题】:Whats wrong with this code? Objective C [closed]这段代码有什么问题?目标C [关闭]
【发布时间】:2014-08-18 11:56:15
【问题描述】:

我似乎无法让它工作,我希望它显示(myXYPoint 的值是,2,4) 这是我的代码。我一直在我的输出区域(lldb)中得到这个。这是来自 stephen g kochan 的《目标 c 编程》一书中的练习,第 50 页问题 7。我尝试将其与答案进行比较,但仍然没有发现问题。我也在第 14 行得到了这个,(线程 1:断点 1.1.2.1)

#import <Foundation/Foundation.h>

//interface section

@interface XYPoint: NSObject
-(void)setAbscissa: (int) x;
-(void)setOrdinate: (int) y;
-(int)abscissa;
-(int)ordinate;

@end

//--implementation section--

@implementation XYPoint
{
int abscissa;
int ordinate;
}
-(void)setAbscissa:(int)x
{
abscissa=x;
}

-(void)setOrdinate:(int)y
{
ordinate=y;
}
-(int) abscissa;
{
return abscissa;
}
-(int) ordinate;
{
return ordinate;
}

@end

//--program section--

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

@autoreleasepool {
    XYPoint *myXYPoint = [[XYPoint alloc] init];
    //It could also be [XYPoint *myXYPoint = [XYPoint new]

    // Set coordinate to 2,4
    [myXYPoint setAbscissa: 2];
    [myXYPoint setOrdinate: 4];
    //setting the coordinates

    // Display the coordinate
    NSLog (@"The value of myXYPoint is: %i,%i", [myXYPoint abscissa], [myXYPoint ordinate]);
    //this is to display the coordinates


}
return 0;

}

【问题讨论】:

  • “我的输出区一直有这个。” - 这是什么”??第 14 行在哪里??
  • 我刚刚尝试了你的代码,我正在努力工作。控制台输出是什么? dropbox.com/s/m5hyexptqi80m6c/…
  • 我通过单击左上角的停止按钮解决了这个问题,然后运行它并且它起作用了,我只需要先停止运行应用程序。谢谢你这么快的帮助。愚蠢的错误,对不起

标签: objective-c xcode output breakpoints nslog


【解决方案1】:

我通过单击 Xcode 左上角的停止按钮解决了这个问题,然后运行它并且它工作正常,我只需要先停止运行应用程序。谢谢你这么快的帮助。愚蠢的错误,对不起。

【讨论】:

    猜你喜欢
    • 2013-04-30
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多