 		withUnsafeMutablePointer(&spinLock, OSSpinLockLock)
 		
 		numberOfRegisteredActivities += 1
-		if numberOfRegisteredActivities > 0 {
-			UIApplication.sharedApplication().networkActivityIndicatorVisible = true
-		}
+		//Lets let the didset of numberOfRegisteredActivities do the work.
+//		if numberOfRegisteredActivities > 0 {
+//			UIApplication.sharedApplication().networkActivityIndicatorVisible = true
+//		}
 		
 		withUnsafeMutablePointer(&spinLock, OSSpinLockUnlock)
 	}

import UIKit
#endif

@availability(iOS, introduced=7.0)
@objc class NetworkActivityController {
	
	/**

		
		let newValue = numberOfRegisteredActivities - 1
		numberOfRegisteredActivities = newValue >= 0 ? newValue : 0
//		if numberOfRegisteredActivities == 0 {
//			UIApplication.sharedApplication().networkActivityIndicatorVisible = false
//		}
		
		withUnsafeMutablePointer(&spinLock, OSSpinLockUnlock)
	}
	
	//MARK: Private
	private var spinLock = OS_SPINLOCK_INIT
	private var activity: Bool = false
	
	/// The number of activities in progress. If the number is greater than 0, the network activity indicator is visible (unless modified by an external source).
	private var numberOfRegisteredActivities: Int = 0 {
		didSet {
			if numberOfRegisteredActivities != oldValue {
				numberOfRegisteredActivitiesChanged()
			}
		}
	}
	
	/* Listens to the change from numberOfRegisteredActivities and acts upon that change */
	private func numberOfRegisteredActivitiesChanged() {
		#if os(iOS)
			if numberOfRegisteredActivities > 0 {
				UIApplication.sharedApplication().networkActivityIndicatorVisible = true
			}
			if numberOfRegisteredActivities == 0 {
				UIApplication.sharedApplication().networkActivityIndicatorVisible = false
			}
		#endif
		if numberOfRegisteredActivities > 0 {
			activity = true
		}
		if numberOfRegisteredActivities == 0 {
			activity = false
		}
		
	}
}