How do I display this Log message in the Debug area using Xcode9?
This looked promising but doesn’t seem like a duplicate question as it addresses issues in Swift.
I am finalising an existing Objective C project but
NSLog disappeared when I updated to Xcode 9. So I’m looking for some setting in Xcode that lets me continue using
NSLog to fine tune the project.
Basic debugging using logging for Swift and Objective-C apps appears to have changed in Xcode 9 as
NSLog messages no longer appear in the Debug area. The window where DEBUG=1 is set no longer looks like Figure 2 The DEBUG preprocessor macro setting in an Xcode project.
As an example, I want to display this string message in the Debug area using Xcode9.
NSString *outputData = @"This should show in Debug area"; NSLog( @"text: %@", outputData );
I studied the latest documentation here or here but so far that has not helped. It may also be worth noting that previously the Debug area would open automatically when I ran the project. Since installing
Xcode9 it no longer does that.
Hopefully the extra information provided in the edits below will suggest to someone where I have yet to look. Thanks.
In the Console area – i.e. the bottom right part of the Debug area – I had All Output selected. So I tried using Debugger output and Target output but there was still no log.
I added these statements in the
#ifndef DEBUG #define NSLog(...) /* suppress NSLog when in release mode #endif
When I ran the code the following appeared in the Issue Navigator.
Unused variable 'outputData'
There seems to be a different place to set DEBUG=1 in Xcode9 (see below).
I inserted a DEBUG macro into the .pch file using the examples suggested in several SO posts here, here, here (all quite old) and even here (making sure to change MyLog back to NSLog). And in each case I was able to report the same issue in the Issue navigator but never in the Debug console. A similar problem (with
Xcode5) was solved here by copying over the files into a new project but I want to avoid this.
My app which was almost finished has so far not had to deal with any of the complex issues that unified logging seeks to address. But I watched the 2016 WWDC video on unified logging and read through its slide show files searching for an example of how to use the appropriate API to do something as basic – print
NSLog live to the console area – the way I did before installing
Xcode9. This may be the wrong approach. But I can’t think of a better way to proceed.
It’s worth noting that when I created a new Objective C project using Xcode9 and ran the above code, the string message appeared in the Console area.
In other words, using Xcode9 the new logging API does work with
NSLog, but only for a new project and not for one created using an earlier version of Xcode.
Enable DEBUG preprocessor macro
3 Solutions Collect From Internet About “How do I display this Log message in the Debug area using Xcode9?”
Rather than writing your debug statement into code, you might try dropping in a breakpoint, right clicking on it, and selecting “Edit Breakpoint”. You should see this menu:
From there, you’ll click “Edit Breakpoint” and you’re presented with this:
From there, you can click “Action” and you’ll see this menu:
You can enter print messages (ex:
myMethodCalled) or variable values (
myIntValue = @myIntValue@), or you can type debugger commands to execute at that spot in the code (ex:
The downside of this approach is the breakpoints aren’t always “sticky” to the line of code you originally drop it in on.
Try this. Navigate to:
Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment Variables
OS_ACTIVITY_MODE and set the value to
leave it empty.
Make sure it is checked!
Hope this helps
A Debug log was enabled in the Console area of Xcode9 after replacing these definitions in the preCompile header
#ifndef DEBUG #define NSLog(...) /* suppress NSLog when in release mode */ #endif
with the following
#ifdef __DEBUG__ #define NSLog(...) /* suppress NSLog when in release mode */ #endif
Environment Variables for
Arguments were set according to the answer above with an additional setting for
Options. Someone more familiar with the unified logging API might explain the particular options but I’m satisfied I have a working solution.
- How to implement video DRM in iOS
- How to get NSData of mp3 using MPMediaPickerController?
- UITableView swipe gesture requires near perfect accuracy
- Submission of ios app: invalid team id
- Disable UITableView horizontal scroll
- Unable to simultaneously satisfy constraints
- Trigger a method in UIViewController from its View
- How to get a Canvas in a Swift Playground
- Using custom fonts in WKWebView
- Scrollview and keyboard Swift
- Reading the iPhone's Ambient Light sensor
- How do I make my exponentiation operator work with all numeric types in Swift?
- How do I draw a filled circle with OpenGL ES on iPhone?
- How to set size of UIImageView equal to size of UIImage?
- XCode Crashing When Opening Project File