iOS  Tree

"All of us do not have equal talent. But , all of us have an equal opportunity to develop our talents.” – A.P.J Abdul Kalam

Network Activity Indicator — May 30, 2017

Network Activity Indicator

To show and hide Network Activity Indicator

Objective c:

- (void)showHideNetworkIndicator {
      if ([[UIApplication sharedApplication]isNetworkActivityIndicatorVisible]) { //If Network indicator is visible
            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:false];
      } else { //If Network indicator is invisible
            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:true];
      }
}

Swift 2.0:

func showHideNetworkIndicator(){
      if UIApplication.sharedApplication().networkActivityIndicatorVisible{
            UIApplication.sharedApplication().networkActivityIndicatorVisible = false
      }else{
            UIApplication.sharedApplication().networkActivityIndicatorVisible = true
      }
}

Swift 3.0:

func showHideNetworkIndicator() {
      if UIApplication.shared.isNetworkActivityIndicatorVisible {
            UIApplication.shared.isNetworkActivityIndicatorVisible = false
      }else{
            UIApplication.shared.isNetworkActivityIndicatorVisible = true
      }
}

iOS Debug mode Logs —

iOS Debug mode Logs

Objective C:

Place this code in your .pch file:
#ifndef NSLog
#ifdef DEBUG
#define NSLog(_format_, ...) NSLog(_format_, ## __VA_ARGS__)
#else
#define NSLog(_format_, ...)
#endif
#endif

Now you can use NSLog for all log messages that should only be printed in your debug builds.

Swift 2.2:

func print(items: Any..., separator: String = " ", terminator: String = "\n") {
      #if DEBUG
            Swift.print(items[0], separator:separator, terminator: terminator)
      #endif
}

Swift 3.0:

func print(_ item: @autoclosure () -> Any, separator: String = " ", terminator: String = "\n") {
      #if DEBUG
            Swift.print(item(), separator:separator, terminator: terminator)
      #endif
}

This executes just in the case where you are printing just one thing, which is usually call in DEBUG mode. That’s because item() is not called in Release mode