Skip to content

Instantly share code, notes, and snippets.

View piyush23dez's full-sized avatar

Piyush piyush23dez

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