我不知道为什么这不起作用,我搜索了它并没有发现任何东西。我是Obj c和xcode的新手。如果我在 - (void)setX:(int)x之前添加了一些东西,但是它没有在它自己的地方,那么代码就可以正常工作了......它的构建成功了,但我确实得到了这个“线程1:断点3.1”在执行中的行是setX。有谁知道为什么这不起作用?
// Program to work with fractions – class version
#import <Foundation/Foundation.h>
//---- @interface section ----
@interface XYPoint: NSObject
-(void) setX: (int) x;
-(void) setY: (int) y;
-(int) getX;
-(int) getY;
@end
//---- @implementation section ----
@implementation XYPoint
{
int xpoint;
int ypoint;
}
-(void) setX: (int) x
{
xpoint = x;
}
-(void) setY: (int) y
{
ypoint = y;
}
-(int) getX
{
return xpoint;
}
-(int) getY
{
return ypoint;
}
@end
//---- program section ----
int main (int argc, char * argv[])
{
@autoreleasepool
{
XYPoint *point = [[XYPoint alloc] init];
[point setX: 4];
[point setY: 3];
NSLog(@"The points are: %i, %i", [point getX], [point getY]);
return 0;
}
}
这并不工作,但这样做:
// Program to work with fractions – class version
#import <Foundation/Foundation.h>
//---- @interface section ----
@interface XYPoint: NSObject
-(void) setX: (int) x;
-(void) setY: (int) y;
-(int) getX;
-(int) getY;
@end
//---- @implementation section ----
@implementation XYPoint
{
int xpoint;
int ypoint;
}
-(void) crap: (int) thing {}
-(void) setX: (int) x
{
xpoint = x;
}
-(void) setY: (int) y
{
ypoint = y;
}
-(int) getX
{
return xpoint;
}
-(int) getY
{
return ypoint;
}
@end
//---- program section ----
int main (int argc, char * argv[])
{
@autoreleasepool
{
XYPoint *point = [[XYPoint alloc] init];
[point setX: 4];
[point setY: 3];
NSLog(@"The points are: %i, %i", [point getX], [point getY]);
return 0;
}
}
好了,所以我就缩进它,所以它会被格式化,以粘贴在这里,当我把它放回它的工作原理...有谁知道发生了什么事?
+1为了建立在这个正确的答案上,第二个代码示例没有停止运行的原因是多余的空函数落在行上,断点将'setX:'从断点移开。所以程序执行永远不会使它与断点一致。 – NJones 2012-03-18 04:23:08
是的,这样做更有意义,谢谢你的回应。 – GnarGnar 2012-03-18 05:04:27