Skip to content

Commit

Permalink
ray wenderlich/chapter 2 - observables
Browse files Browse the repository at this point in the history
  • Loading branch information
hlazarpesic committed Nov 10, 2019
1 parent e6863d1 commit 4565816
Show file tree
Hide file tree
Showing 380 changed files with 36,310 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added Coordinator Pattern/.DS_Store
Binary file not shown.
Binary file modified RxSwift/.DS_Store
Binary file not shown.
Binary file modified RxSwift/Mastering RxSwift in iOS/.DS_Store
Binary file not shown.
Binary file modified RxSwift/Reactive Programming With Swift 4/.DS_Store
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import UIKit
import RxSwift

enum MyError: Error {
case anyError
}

enum FileReadError: Error {
case fileNotFound
case unreadable
case encodingFailed
}

var str = "Hello, playground"
var db = DisposeBag()

//var observable = Observable.from(["demo", "demo 2"])
//observable.subscribe(onNext: { item in
// print(item)
//}).disposed(by: db)

//var observable1 = Observable.range(start: 0, count: 10)
//observable1.subscribe(onNext: { num in
// print(num)
// }).disposed(by: db)


//let observable = Observable<String>.create{ observer in
// observer.onNext("1")
// observer.onError(MyError.anyError)
// observer.onCompleted()
// return Disposables.create()
//}
//
//observable.subscribe(
// onNext: { item in
// print(item)
//}, onError: { error in
// print(error)
//}, onCompleted: {
// print("completed")
//}, onDisposed: {
// print("disposed")
//})
// .disposed(by: db)

//MARK: Creating Observable Factories
//var flip = false
//
//let factories = Observable<Int>.deferred {
//
// flip = !flip
//
// if flip {
// return Observable.of(1, 2, 3)
// } else {
// return Observable.of(4, 5, 6)
// }
//}
//
//for _ in 0...3 {
// factories.subscribe( onNext: { item in
// print(item, terminator: " ")
// }).disposed(by: db)
//}



//MARK: Using Traits

func loadText(from name: String) -> Single<String> {
return Single.create{ single in

let disposable = Disposables.create()

guard let path = Bundle.main.path(forResource: name, ofType: "txt") else {
single(.error(FileReadError.fileNotFound))
return disposable
}


guard let data = FileManager.default.contents(atPath: path) else {
single(.error(FileReadError.unreadable))
return disposable
}

guard let contents = String(data: data, encoding: .utf8) else {
single(.error(FileReadError.encodingFailed))
return disposable
}

single(.success(contents))
return disposable
}
}

loadText(from: "").subscribe(
onSuccess: { content in
print(content)
}, onError: { error in
print(error)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
Loading

0 comments on commit 4565816

Please sign in to comment.