-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ray wenderlich/chapter 2 - observables
- Loading branch information
1 parent
e6863d1
commit 4565816
Showing
380 changed files
with
36,310 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
...th Swift 4/Rective programming.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...ctive programming.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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
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 added
BIN
+8.99 KB
.../playground.xcworkspace/xcuserdata/hlazarpesic.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+6 KB
RxSwift/RxSwift 2nd Edition - Ray Wenderlich/Chapter 2 - Observables/.DS_Store
Binary file not shown.
Binary file added
BIN
+6 KB
RxSwift/RxSwift 2nd Edition - Ray Wenderlich/Chapter 2 - Observables/Observables/.DS_Store
Binary file not shown.
102 changes: 102 additions & 0 deletions
102
...Ray Wenderlich/Chapter 2 - Observables/Observables/MyPlayground.playground/Contents.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
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) | ||
}) |
4 changes: 4 additions & 0 deletions
4
...derlich/Chapter 2 - Observables/Observables/MyPlayground.playground/contents.xcplayground
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
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> |
Oops, something went wrong.