string value always shows nil in objective C

前端 未结 4 468
野的像风
野的像风 2021-02-01 01:32

I have upgraded to Xcode 5.0. And when I run an app in debug mode and try to print an NSString value in console, it gives me the below error. Any ideas?

         


        
相关标签:
4条回答
  • 2021-02-01 02:08

    The reason is stated in the error message: it may have been optimized out.. this means that you are compiling and running your code in an optimized manner.

    you gotta change your compiler optimization level from Fastest,Smallest to none:

    • go to your target build settings
    • search for optimization level
    • change it to none (whatever mode you are in ie debugging, distribution or release)
    • profit

    do the same for your project settings

    0 讨论(0)
  • 2021-02-01 02:24

    You might be trying to debug in the "release Scheme". Go to "Product/Scheme/Edit Scheme" and pick the "run" in the left panel. Then change the build configuration to "debug".

    0 讨论(0)
  • 2021-02-01 02:30

    One alternate answer: instead of fixing "it may have been optimized out" by removing the optimization, you can stop it from being optimized by using the variable.

    So, in your question, if you do something with stringValue:

    NSString *stringValue = [[self.responseArray objectAtIndex:i] valueForKey:@"merchant_name"]; 
    NSLog(@"%@", stringValue);
    

    stringValue will no longer be optimized out because you're using it.

    If you want to see all instances of optimized-out variables in your project, Use Product -> Analyze to analyze your project. Any "Dead store" warnings (in which a value is stored, and never read) will be optimized out at compile time if you have compiler optimization turned on.

    0 讨论(0)
  • 2021-02-01 02:31

    Make sure you are in debug mode. Go Edit Scheme > Build Configuration > Debug

    0 讨论(0)
提交回复
热议问题