Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // multiprocess
- //
- // Created by Alexander Kolov on 30.1.15.
- // Copyright (c) 2015 Alexander Kolov. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var button: UIButton!
- var lockQueue = dispatch_queue_create("lockQueue", nil)
- lazy var queue: NSOperationQueue = {
- let queue = NSOperationQueue()
- queue.maxConcurrentOperationCount = 10
- return queue
- }()
- lazy var memory: [[String]] = {
- var memory = [[String]]()
- return memory
- }()
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- @IBAction func didTapButton(sender: UIButton) {
- var operations = [NSBlockOperation]()
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
- for i in 0...10 {
- let operation = NSBlockOperation() {
- var arr = [String]()
- for a in UnicodeScalar("a").value...UnicodeScalar("z").value {
- arr.append(String(format: "%c", a))
- }
- dispatch_sync(self.lockQueue) {
- self.memory.append(arr)
- }
- }
- operations.append(operation)
- }
- self.queue.addOperations(operations, waitUntilFinished: true)
- println("\(self.memory)")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement