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
class GermanShephard: Barker, DrugSniffer { | |
} | |
class BelgianMalinois: Barker, Swimmer, DrugSniffer { | |
} | |
class Poodle: Barker, Swimmer { | |
} | |
let belgian = BelgianMalinois() |
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
class Foo { | |
var value: Int = 0 | |
func doIt() { | |
for index in 0..<10 { | |
value = index | |
} | |
print(value) | |
} | |
} | |
} |
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
func threadOperation() { | |
let foo = Foo() | |
let queue = DispatchQueue.global(qos: .default) | |
for _ in 0..<10 { | |
queue.async { | |
foo.doIt() | |
} | |
} | |
} |
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
class Foo { | |
var value: Int = 0 | |
func doIt() { | |
for index in 0..<10 { | |
value = index | |
} | |
IP -> print(value) | |
} | |
} |
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
class Foo { | |
var value: Int = 0 | |
func doIt() { | |
for index in 0..<10 { | |
IP -> value = index | |
} | |
print(value) | |
} | |
} |
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
func threadSafeOperation() { | |
let foo = Foo() | |
let queue = DispatchQueue.global(qos: .default) | |
let locker = NSLock() | |
for _ in 0..<4 { | |
queue.async { | |
locker.lock() | |
foo.doIt() | |
locker.unlock() |
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
func threadSafeOperation() { | |
let foo = Foo() | |
let queue = DispatchQueue(label: "com.apple.serial") | |
for _ in 0..<4 { | |
queue.sync { | |
foo.doIt() | |
} | |
} | |
} |
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
@objc class Person: NSObject { | |
@objc dynamic var name = "Mark Swift" | |
} |
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
let mark = Person() | |
mark.observe(\Person.name, options: .new) { person, change in | |
print("I'm now called \(person.name)") | |
} | |
mark.name = "Mark Zukerberg" |
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
let nc = NotificationCenter.default | |
nc.post(name: Notification.Name("UserLoggedIn"), object: nil) |
OlderNewer