<commit_before>//
//  DEMO.swift
//  DEMO
//
//  Created by <NAME> on 8/22/16.
//  Copyright © 2016 DingSoung. All rights reserved.
//

import Foundation

public class TESTMODEL:NSObject {
    dynamic func printlog(title:String) {
        print("TESTMODEL print log:\(title)")
    }
}

public extension NSObject {
    dynamic class func printlog2(title:String) {
        print("TESTMODEL2 print log:\(title)")
    }
}


public class DEMO: NSObject {
    
    enum OperateType: Error {
        case noParameter
        case emptyParameter
    }
    class func operate(parameter: String?) throws -> String {
        guard let para = parameter else {
            throw OperateType.noParameter
        }
        if para.characters.count > 0 {
        } else {
            throw OperateType.emptyParameter
        }
        return para.lowercased()
    }
    
    class public func testNSOperationTryCatch() -> Void {
        OperationQueue().addOperation {
            do {
                let _ = try operate(parameter: nil)
            } catch let error {
                print(error)
            }
        }
        // 实验证明   在Swift中写不出  在try catch 中调用 异步线程的代码
    }
    
    
    class public func testGCDQOS() -> Void {
        

        
        
        
        
        let  serialQueue = DispatchQueue(label: "serial queue")
        
        OperationQueue
        
        
        
        let queue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default)
        for i in 0..<500 {
            queue.async {
                print("\(i) at \(Thread.current)")
            }
        }
    }
    
    class public func testNSOperationQOS() -> Void {
        let queue = OperationQueue()
        queue.maxConcurrentOperationCount = 10
        for i in 0..<500 {
            queue.addOperation {
               print("\(i) at \(Thread.current)")
            }<commit_msg>clean<commit_after>//
//  DEMO.swift
//  DEMO
//
//  Created by <NAME> on 8/22/16.
//  Copyright © 2016 DingSoung. All rights reserved.
//

import Foundation

public class TESTMODEL:NSObject {
    dynamic func printlog(title:String) {
        print("TESTMODEL print log:\(title)")
    }
}

public extension NSObject {
    dynamic class func printlog2(title:String) {
        print("TESTMODEL2 print log:\(title)")
    }
}


public class DEMO: NSObject {
    
    enum OperateType: Error {
        case noParameter
        case emptyParameter
    }
    class func operate(parameter: String?) throws -> String {
        guard let para = parameter else {
            throw OperateType.noParameter
        }
        if para.characters.count > 0 {
        } else {
            throw OperateType.emptyParameter
        }
        return para.lowercased()
    }
    
    class public func testNSOperationTryCatch() -> Void {
        OperationQueue().addOperation {
            do {
                let _ = try operate(parameter: nil)
            } catch let error {
                print(error)
            }
        }
        // 实验证明   在Swift中写不出  在try catch 中调用 异步线程的代码
        
        
        let queue = OperationQueue()
        static var name:String?
        for time in 0..<100 {
            queue.addOperation {
                name = "\(time)"
            }
        }
    }
    
    
    class public func testGCDQOS() -> Void {
        let  queue = DispatchQueue(label: "serial queue")
        for i in 0..<500 {
            queue.async {
                print("\(i) at \(Thread.current)")
            }
        }
    }
    
    class public func testNSOperationQOS() -> Void {
        let queue = OperationQueue()
        queue.maxConcurrentOperationCount = 10
        for i in 0..<500 {
            queue.addOperation {
               print("\(i) at \(Thread.current)")
            }
{'fraction_non_alphanumeric': 0.09559214020180563, 'fraction_numerical': 0.012745618693574084, 'mean_word_length': 1.513008672448299, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 15, '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': '3785247', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1088, 'n_words': 268}