<commit_before>/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information

Abstract:
Contains the code to manage the visibility of the network activity indicator
*/

import UIKit

/**
    An `OperationObserver` that will cause the network activity indicator to appear 
    as long as the `Operation` to which it is attached is executing.
*/
public struct NetworkObserver: OperationObserver {
    // MARK: Initilization

    init() { }
    
    public func operationDidStart(operation: Operation) {
        dispatch_async(dispatch_get_main_queue()) {
            // increment the network indicator's "retain count"
            NetworkIndicatorController.sharedIndicatorController.networkActivityDidStart()
        }
    }
    
    public func operation(operation: Operation, didProduceOperation newOperation: NSOperation) { }
    
    public func operationDidFinish(operation: Operation, errors: [NSError]) {
        dispatch_async(dispatch_get_main_queue()) {
            // Decrement the network indicator's "reference count".
            NetworkIndicatorController.sharedIndicatorController.networkActivityDidEnd()
        }
    }
    
}

/// A singleton to manage a visual "reference count" on the network activity indicator.
private class NetworkIndicatorController {
    // MARK: Properties

    static let sharedIndicatorController = NetworkIndicatorController()

    private var activityCount = 0
    
    private var visibilityTimer: Timer?
    
    // MARK: Methods<commit_msg>Fixes NetworkObserver init visibility<commit_after>/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information

Abstract:
Contains the code to manage the visibility of the network activity indicator
*/

import UIKit

/**
    An `OperationObserver` that will cause the network activity indicator to appear 
    as long as the `Operation` to which it is attached is executing.
*/
public struct NetworkObserver: OperationObserver {
    // MARK: Initilization

    public init() { }
    
    public func operationDidStart(operation: Operation) {
        dispatch_async(dispatch_get_main_queue()) {
            // increment the network indicator's "retain count"
            NetworkIndicatorController.sharedIndicatorController.networkActivityDidStart()
        }
    }
    
    public func operation(operation: Operation, didProduceOperation newOperation: NSOperation) { }
    
    public func operationDidFinish(operation: Operation, errors: [NSError]) {
        dispatch_async(dispatch_get_main_queue()) {
            // Decrement the network indicator's "reference count".
            NetworkIndicatorController.sharedIndicatorController.networkActivityDidEnd()
        }
    }
    
}

/// A singleton to manage a visual "reference count" on the network activity indicator.
private class NetworkIndicatorController {
    // MARK: Properties

    static let sharedIndicatorController = NetworkIndicatorController()

    private var activityCount = 0
    
    private var visibilityTimer: Timer?
    
    // MARK: Methods
{'fraction_non_alphanumeric': 0.06763285024154589, 'fraction_numerical': 0.00322061191626409, 'mean_word_length': 3.380818053596615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '332160', 'n_tokens_mistral': 757, 'n_tokens_neox': 726, 'n_words': 255}