This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DispatchQueue.global().async { | |
| print("Generic global queue") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DispatchQueue.global(qos: .userInteractive).async { | |
| print("We're on a global concurrent queue!") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| URLSession.shared.dataTask(with: url) { data, response, error in | |
| if let data = data { | |
| DispatchQueue.main.async { // UI work | |
| self.label.text = String(data: data, encoding: .utf8) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ViewController: UIViewController { | |
| let concurrent = DispatchQueue(label: "com.besher.concurrent", attributes: .concurrent) | |
| let isolation = DispatchQueue(label: "com.besher.isolation", attributes: .concurrent) | |
| private var _array = [1,2,3,4,5] | |
| var threadSafeArray: [Int] { | |
| get { | |
| return isolation.sync { | |
| _array | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ViewController: UIViewController { | |
| let concurrent = DispatchQueue(label: "com.besher.concurrent", attributes: .concurrent) | |
| var array = [1,2,3,4,5] | |
| override func viewDidLoad() { | |
| for _ in 0...1 { | |
| race() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // add this after the last async statement, | |
| // still inside starterQueue.async | |
| backgroundQueue.sync {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum Color: String { | |
| case blue = "🔵" | |
| case white = "⚪️" | |
| } | |
| func output(color: Color, times: Int) { | |
| for _ in 1...times { | |
| print(color.rawValue) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func processImage(data: Data) -> UIImage? { | |
| guard let image = UIImage(data: data) else { return nil } | |
| // calling an expensive function | |
| let processedImage = upscaleAndFilter(image: image) | |
| return processedImage | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ACTION = build | |
| AD_HOC_CODE_SIGNING_ALLOWED = NO | |
| ALTERNATE_GROUP = staff | |
| ALTERNATE_MODE = u+w,go-w,a+rX | |
| ALTERNATE_OWNER = grantdavis | |
| ALWAYS_SEARCH_USER_PATHS = NO | |
| ALWAYS_USE_SEPARATE_HEADERMAPS = YES | |
| APPLE_INTERNAL_DEVELOPER_DIR = /AppleInternal/Developer | |
| APPLE_INTERNAL_DIR = /AppleInternal | |
| APPLE_INTERNAL_DOCUMENTATION_DIR = /AppleInternal/Documentation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func setupAnimator() { | |
| let context = (view: self.view, | |
| navigationItem: self.navigationItem, | |
| parent: self.parent | |
| ) | |
| let anim = UIViewPropertyAnimator(duration: 2.0, curve: .linear) { | |
| context.view?.backgroundColor = .red | |
| context.navigationItem.rightBarButtonItems?.removeAll() |