convert NSData Length from bytes to megs

There are 1024 bytes in a kilobyte and 1024 kilobytes in a megabyte, so… NSLog(@”File size is : %.2f MB”,(float)myData.length/1024.0f/1024.0f); Mind you, this is a simplistic approach that couldn’t really properly accommodate for byte sizes below 1,048,576 bytes or above 1,073,741,823 bytes. For a more complete solution that can handle varying file sizes, see: ObjC/Cocoa … Read more

How to print NSMutableURLRequest?

.allHTTPHeaderFields returns a dictionary with the header content: NSLog(@”%@”, [request allHTTPHeaderFields]); // { // “Accept-Language” = “en;q=1”; // “Content-Length” = 190706; // “Content-Type” = “multipart/form-data; boundary=Boundary+D90A259975186725”; // “User-Agent” = “…”; // } Or for specific field: NSString *field = @”Content-Type”; NSLog(@”%@”,[request valueForHTTPHeaderField:field]); // multipart/form-data; boundary=Boundary+D90A259975186725

Any way to print in color with NSLog?

You can use Apple Color Emoji to add some color to your Log output like this: if ([self isKindOfClass:[UITableViewController class]]) NSLog(@”💙 Table View controller Will appear: %@”, NSStringFromClass([self class])); else if ([self isKindOfClass:[UINavigationController class]]) NSLog(@”💜 Navigation controller Will appear: %@”, NSStringFromClass([self class])); else NSLog(@”💛 View controller Will appear: %@”, NSStringFromClass([self class])); Because the above code … Read more

NSLog not printing to console

Well, this is embarrassing. The console got deactivated somehow and I was actually watching the variables window. Pressing Shift +  + C did the trick. Many thanks to Robert King on this thread: https://devforums.apple.com/message/565880#565880

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)