Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string value always shows nil in objective C

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?

error: warning: couldn't get cmd pointer (substituting NULL): Couldn't load '_cmd' because its value couldn't be evaluated Couldn't materialize struct: the variable 'stringValue' has no location, it may have been optimized out Errored out in Execute, couldn't PrepareToExecuteJITExpression 

Here is the code:

NSString *stringValue = [[self.responseArray objectAtIndex:i] valueForKey:@"merchant_name"];  
like image 919
Arun Avatar asked Oct 01 '13 08:10

Arun


People also ask

How do I check if a string is nil in Objective C?

You can check if [string length] == 0 . This will check if it's a valid but empty string (@"") as well as if it's nil, since calling length on nil will also return 0.

What does @property do in Objective C?

The goal of the @property directive is to configure how an object can be exposed. If you intend to use a variable inside the class and do not need to expose it to outside classes, then you do not need to define a property for it.


2 Answers

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

like image 171
abbood Avatar answered Sep 21 '22 13:09

abbood


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

like image 30
Mercurial Avatar answered Sep 17 '22 13:09

Mercurial