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"];
- Swift 3.1: Crash when custom error is converted to NSError to access its domain property
- How to create an object depending on a String in Swift?
- Importing and querying through an SQLite database in Swift - iOS
- iPhone - Draw transparent rectangle on UIView to reveal view beneath
- Xcode 7.2 bug: library not found for -lGoogleAnalyticsServices
- UITableViewCell Set Selected Image
4 Solutions Collect From Internet About “string value always shows nil in objective C”
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
- go to your target build settings
- search for optimization level
- change it to none (whatever mode you are in ie debugging, distribution or release)
do the same for your project settings
Make sure you are in debug mode. Go Edit Scheme > Build Configuration > Debug
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”.
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
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.
- Using different storyboards for different screen sizes? universal xcode app
- iOS 8 beta – Today extension doesn't recognize embedded framework
- How do I read an Xcode crash report?
- Application will enter background -> go to root view menu
- How to get ts frame from DJI phantom camera delegate for RTMP streaming to server
- How to upload the Users profile pic and how to fetch that profile pic from another users device?
- Objective C: Reading text files
- Return Bool in Alamofire closure
- Register for messages from collabd like XCSBuildService to receive Xcode Bots integration number
- Can someone explain dispatch_async() for me in this scenario
- UISwitch setThumbTintColor causing crash (iOS 6 only)?
- If statement with dates
- Can one open a watchOS app from an iOS app?
- Swift: download image from Internet and cache them doesn't work properly. need suggestions
- Insertion-Order Dictionary (like Java's LinkedHashMap) in Swift?