Last active
August 7, 2019 18:13
-
-
Save programming086/38217c9b380243a7121eda33c8876333 to your computer and use it in GitHub Desktop.
Incorrect example for Yandex iOS course `Создаёте заметку, копируете ее, меняете поле цвета в одной очереди асинхронно, из другой очереди читаете/пишете цвет из копии заметки`
This file contains 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
import Foundation | |
import UIKit | |
struct Note { | |
enum Importance: UInt { | |
case unimportant = 0, normal, important | |
} | |
let uid: String | |
var title: String | |
var content: String | |
var color: UIColor | |
var importance: Importance | |
var selfDestructDate: Date? | |
init(uid: String = UUID().uuidString, title: String, content: String, color: UIColor = .white, importance: Importance, destructDate: Date? = nil) { | |
self.uid = uid | |
self.title = title | |
self.content = content | |
self.importance = importance | |
self.color = color | |
selfDestructDate = destructDate | |
} | |
} | |
var a = Note(title: "Note 1", content: "Text 1", importance: .normal) | |
var b = a | |
DispatchQueue.global().async { | |
a.color = .red | |
a.title = "Note changed 1" | |
a.content = "Text changed 1" | |
a.importance = .important | |
a.selfDestructDate = Date() | |
DispatchQueue.main.async { | |
sleep(2) | |
print(">> a \(a)") | |
} | |
} | |
DispatchQueue.global(qos: .utility).async { | |
sleep(3) | |
print(">> utility: b \(b)") | |
} | |
DispatchQueue.global(qos: .background).async { | |
print(">> background: b \(b)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OUTPUT