开发者

How can I step though [messages] in XCode/Objective-C for iOS apps?

Update: There seems to be an issue with having a method that returns a double/float and trying to step-into. Since I was able to step into setOperand but not preformOperation, I tried changing preformOperation to - (void) from - (double) and everything worked as expected. Playing with things a bit more, I tried (int), (float), and (id).

(int) and (id) both allowed me to step-into the method without any issue. (float) however exhibited the same behavior as (double) where xcode will just step over the line instead of allowing me to step into.

Does anyone have any thoughts as to why this is happening?

Original: I've recently decided to pick up Obj-C/iOS programming and I'm a bit stuck when trying to step through code.

If I have the following methods in the brain:

//CalcBrain.h
@interface CalcBrain : NSObject {
double operand;
NSString * waitingOperation;
double waitingOperand;
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end

And in the view controller:

//CalcViewControl.m
...
- (CalcBrain *)brain
{    
    if(!brain)
        brain = [[CalcBrain alloc] init];
    return brain;
}
.开发者_如何学C..   
- (IBAction)operationPressed:(UIButton *)sender
{
    if(inMiddleOfOps)
    {
            [[self brain] setOperand:[[display text] doubleValue]];
            inMiddleOfOps = NO;
    }
    NSString *operation = [[sender titleLabel] text];
    double result = [[self brain] performOperation:operation];

   [display setText:[NSString stringWithFormat:@"%g", result]];
}
...

If I set a breakpoint on: double result = [[self brain] performOperation:operation];

And then "step-into", I'll see it go into the [self brain] section of code in CalcViewControll.m, however once I return from that section, it goes right onto the next line. Coming from a C/C++ background this is not the behavior I expected, instead I was thinking/hoping that it would head into the CalcBrain.m and let me step through the performOperation method inside of the "brain".

I can get this functionality if I add a breakpoint on the first line of the performOperation method - however this is not ideal.

I understand that these are messages being sent, but can you really not step inside to see what is happening? Am I missing something obvious? I'm using Xcode 3.2.6 if it makes a difference.

edit:

[self brain] is not nil.

I'm running/building in the debug config (no optimizations are set).

I've tried breaking the line in question into two separate lines but still does not work as expected.


You should just be able to hit "step into" again while it's still on that line. It should work the way you expect it to-- when a line has several nested calls on it (like your example-- the accessor is one method and the -performOperation: is another), the "step into" behavior will go into them in their order of execution. They'll come back up and then step into the next one.

Are you sure you're not hitting "Step over" when you come back from the -brain accessor?

If it's really not working like it should, maybe you're debugging a release build, or some other binary that is significantly optimized and you're seeing the normal confusion that a debugger goes through when source-stepping?


[self brain] isn't returning nil by chance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜