How to change NSString value while debugging in Xcode?

前端 未结 4 1903
失恋的感觉
失恋的感觉 2020-12-23 13:35

When I\'m stopped at a break point in Xcode, I can see the value of NSString variables. How can I change them? I can change int or double variables, but not NSString.

4条回答
  •  有刺的猬
    2020-12-23 14:11

    You can but you have to call code from the debugger command prompt. For example, say you have a breakpoint fire off right after this line:

    NSString *myString = @"My current string";
    

    Then at the (gdb) prompt type:

    call myString = @"My new string"
    

    You can po myString before changing the string and after you change it to verify that it has changed.

    Another example: Say you wanted to change a view controller's title. You can use the setter. *Note: dot notation is not supported at the debugger command line. For example let the view load and then set a breakpoint somewhere during the lifetime of your view controller. Then do this:

    call (id)[self setTitle:@"New Title"]
    

    Continue running the program and you should see your view controller's title update.

提交回复
热议问题