Why are NSLogs in Xcode 8 cut off? - ios

I just installed Xcode 8 and I use NSLogs to see my server response and for other verifications.However, my NSLogs with my server response (in JSON) are getting cut off.Any Ideas?I am using objective-c and running my app on a real device.

I was able to figure this out with the help of This question
You have to create a global header (YourProjectName.pch) Then post this line:
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
Then you can call NSLog like normal from any view like NSLog(#"My array data: %#", anArray);

Related

NSDATA description returning nil

NSData description returning nil and making the NSData object nil. My code has stopped working and I would like to get this working again.
If I compile my code in Xcode 10 it will get the NSData description fine. But if I use Xcode 11 it will give me nil as the description and it will make the NSData nil as well. I'm confused as to how this is happening. Is this because it's still a beta release? Is this kind of thing normal in beta releases? I just want to make sure my code still works before the new iOS 13 an iPAD OS 13 come out.
NSString *result = [[data description] stringByReplacingOccurrencesOfString:#" " withString:#""];
See https://twitter.com/steipete/status/1174111017900503040 - iOS 13 behavior (written at time of GM seed 2).
As others have said, you should not be using [NSData description] this way.

iOS app debug without cable

Is it possible to log to a file on the iPhone (or get at the console output somehow) to read it later, or perhaps directly from the phone?
I need to debug an app that is using a cable-connected accessory device, so it cannot be connected to XCode at the same time.
You can make use of PonyDebugger.
I've been using it a lot to debug networking and CoreData resources, but it also allows logging to the console with PDLog.
PonyDebugger is a remote debugging toolset. It is a client library and gateway server combination that uses Chrome Developer Tools on your browser to debug your application's network traffic and managed object contexts.
Some recommendations:
It works better in Safari than Chrome.
Look into repo issues for making it work in your OSX version if needed. I have it working on El Capitan.
Automatic connection didn't work for me, try using local IP gateway address instead:
e.g. [debugger connectToURL:[NSURL URLWithString:#"ws://192.168.0.12:9000/device"]];
Kevin Xi's approach is OK. You can also redirect NSLog output to the file using following code in AppDelegate's didFinishLaunchingWithOptions method:
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [allPaths objectAtIndex:0];
NSString *pathForLog = [documentsDirectory stringByAppendingPathComponent:#"log.txt"];
freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+", stderr);
It is really a pity that Apple doesn't provide WiFi debugging for Xcode, but for your question, the answer is YES, you can definitely redirect NSLog to a log file, you can try this approach:
// this will redirect all NSLog in your project, add it to PCH file.
#define NSLog(args...) writeLog(__PRETTY_FUNCTION__, __LINE__, args)
void writeLog(const char *function, int lineNumber, NSString *format, ...) {
// basic log content.
va_list ap;
va_start (ap, format);
NSString *msg = [[NSString alloc] initWithFormat:format arguments:ap];
va_end (ap);
// add function name, and line number.
NSString *log = [NSString stringWithFormat:#"%s line %d $ %#", function, lineNumber, msg];
// add your own code to write `log` into a text file.
....
}
Note: if you are using some libraries which also write logs to Console, this macro won't redirect those logs to your log file, it will only work with NSLog in your own source files.
As far as I know, this is not possible.
You can eventually use a free and excellent solution like bugfender which will allow you to get the data logged by NSLog remotely. This could help you.

Unity / Objective-C: Trouble converting char* to NSString

I have what should be a dead-simple piece of code that is failing for me in strange ways.
void MediaShare(char* text, char* furl) {
NSString *status = [NSString stringWithUTF8String: text];
NSString *media = [NSString stringWithUTF8String: furl];
[[SocialShare sharedInstance] mediaShare:status media:media];
text is just a line of text for Twitter sharing, and furl is just a file location string. I am getting a crash down past this function that comes down to bad data getting passed. Putting a breakpoint at the head of this function yields the following-
Image of Xcode variable monitor
The two values look fine, although not sure if the * values that only contain the first char are a problem.
Anyway, jumping to the end, and status and media appear to be converted to hex values.
Converted to hex values?
Any ideas? To give the full story, this is a Unity plug-in. I am simply passing in two strings from Unity C# to this function.
Thanks so much.
The code looks fine so far, if the input values are well formed C char* strings that can be interpreted as an UTF-8 encoded string.
status and media being hex values at the end of the function hint that they are. Both are pointers to Objective-C objects, so this is expected. Print them to the debug console or use po status at the debug console to check their contents (it will print the result of the -description method of status which is the string content in that case).
The subsequent crash might be caused elsewhere in the code.
What's the crash's log output?

Remove NSLog header

Below is a typical NSLog output from the console. Can I get rid of the bold text?
2013-06-09 22:17:02.351 ProjectName[33584:907] MyWantedText
I want to cut out the console text, and compare it (by diff), to a similar log. I don't want time data etc that only will produce false positives.
Is it possible to make my own console write method, MyNsLog, if I can't alter de behavior NSLog?
for your app put this into your Prefix header:
#undef NSLog
#define NSLog(fmt, ...) printf("%s", [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String])
but id actually rather leave nslog and just use another logging mechanism like ddlog or so
Simple,
NSString *text = #"Some text here";
printf("%s", [text UTF8String]);
Result,
Some text here
You can't rid of the bold text, NSLog() adds the capability to print out objects variables. Also as you can see, adds the program name, the date, the time.
You can change for another logging function like printf

Disable date/process ID in xcode output

How can I remove date and process ID from output window in XCode? They only take up a lot of space without real value.
Use this macro, this will override the default behavior of NSLog,
#define NSLog(STRING, ...) printf("%s\n", [[NSString stringWithFormat:STRING, ##__VA_ARGS__] UTF8String]);

Resources