Skip to content

Instantly share code, notes, and snippets.

View deda9's full-sized avatar
๐Ÿ
Learning is always fun

Bassem Qoulta deda9

๐Ÿ
Learning is always fun
View GitHub Profile
@deda9
deda9 / RxObservableInterval.swift
Created June 18, 2019 08:43
Create RxObservable with interval
func createRxObservable() {
let source: Observable<Int> = Observable.interval(1, scheduler: ConcurrentDispatchQueueScheduler.init(qos: DispatchQoS.background)).take(3)
source
.subscribe(onNext: { number in
print("Second: ", number)
}, onError: { _ in print("On Error") },
onCompleted: { print("Complete") },
onDisposed: nil)
}
@deda9
deda9 / RxObservableFrom.swift
Last active June 18, 2019 08:41
Create RxObservable with from
func createRxObservable() {
let source = Observable<Int>.from([1, 2, 3, 4, 6, 7])
source
.subscribe(onNext: { number in
print("Current emitted number: ", number)
}, onError: { _ in print("On Error") },
onCompleted: { print("Complete") },
onDisposed: nil)
@deda9
deda9 / RxObservableDefer.swift
Created June 18, 2019 08:37
Create RxObservable with defer
func createRxObservable() {
let source: Observable<Int> = Observable.deferred {
let source: Observable<Int> = Observable.create { observer in
for i in 1...5 {
observer.on(.next(i))
}
observer.on(.completed)
return Disposables.create()
}
return source
@deda9
deda9 / RxObservableCreate.swift
Last active June 18, 2019 08:26
Create RxObservable with create
func createRxObservable() {
let source: Observable<Int> = Observable.create { observer in
for i in 1...5 {
observer.on(.next(i))
}
observer.on(.completed)
return Disposables.create()
}
source
@deda9
deda9 / DispatchGroup.swift
Last active June 12, 2018 22:36
How to create DispatchGroup
let group = DispatchGroup()
group.enter()
let dispatchQueue1 = DispatchQueue.init(label: "dispatchQueue")
dispatchQueue1.sync {
for i in 0..<5 {
print("DispatchQueue X ", i)
}
group.leave()
@deda9
deda9 / GlobalDispatchQueueWithDifferentPriority.swift
Last active December 20, 2020 18:48
How to create global dispatch queue with different priority
//With Different priority
let dispatchQueue1 = DispatchQueue(label: "Queue 1", qos: .userInteractive)
let dispatchQueue2 = DispatchQueue(label: "Queue 2", qos: .background)
dispatchQueue1.async {
for i in 0..<5 {
print("DispatchQueue X ", i)
}
}
@deda9
deda9 / GlobalDispatchQueue.swift
Last active December 20, 2020 18:44
How to create global dispatch queue
let dispatchQueue = DispatchQueue(label: "Background", attributes: .concurrent)
dispatchQueue.async {
for i in 0..<5 {
print("DispatchQueue X ", i)
}
}
dispatchQueue.async {
for i in 5..<10 {
print("DispatchQueue Y ", i)
@deda9
deda9 / NSOperationQueue.swift
Created June 7, 2018 23:02
How to create NSOperationQueue
let operationQueue1 = OperationQueue.init()
let operation1 = BlockOperation.init()
operation1.addExecutionBlock {
print("I am operation execution block injected in the operation1")
}
operationQueue1.addOperation(operation1)
operationQueue1.addOperation {
print("I am operation execution block injected direct to queue by operation")
@deda9
deda9 / DependencyNSOperationBlock.swift
Created June 7, 2018 22:50
How to create Dependencies for NSOperationBlock in swift
let operationQueue = OperationQueue()
let op0 = BlockOperation()
op0.completionBlock = {
print("op0 completionBlock")
}
op0.addExecutionBlock {
print("op0 executionBlock #1")
}
@deda9
deda9 / ConcurrencyCustomOperationBlock.swift
Created June 7, 2018 22:38
How to create Concurrency custom operation block
enum OperationState: Int {
case ready
case executing
case finished
}
class CustomOperationBlock: Operation{
private var state: OperationState!