# Subjects as observers, not observables, page 67

**URL:** <https://forums.kodeco.com/t/subjects-as-observers-not-observables-page-67/58978>\
**Category:** RxSwift\
**Created:** [January 4, 2019, 12:44pm UTC](https://forums.kodeco.com/t/subjects-as-observers-not-observables-page-67/58978 "2019-01-04T12:44:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evs718](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/evs718/32/81494_2.png) [@evs718](https://forums.kodeco.com/u/evs718)\
**Post date:** [January 4, 2019, 12:44pm UTC](https://forums.kodeco.com/t/subjects-as-observers-not-observables-page-67/58978/1 "2019-01-04T12:44:19Z")

</div>

“… is something that can act as **both** an **observable** and as an **observer**. And that something is called a Subject.” - page 67

Perhaps this is explained further along in the book however, as far as I have noticed, in the first eleven chapters it is not explained how or why a person would use a subject as an **observer**. Subjects are used extensively in these chapters as observables but not as observers. Does a discussion of this come up later in the book?

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [January 4, 2019, 1:02pm UTC](https://forums.kodeco.com/t/subjects-as-observers-not-observables-page-67/58978/2 "2019-01-04T13:02:23Z")

</div>

@scotteg Do you have any feedback about this? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![scotteg](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/scotteg/32/109788_2.png) [@scotteg](https://forums.kodeco.com/u/scotteg)\
**Post date:** [January 22, 2019, 6:03pm UTC](https://forums.kodeco.com/t/subjects-as-observers-not-observables-page-67/58978/3 "2019-01-22T18:03:22Z")

</div>

Hi @evs718, it means that a subject can be subscribed to, i.e., to respond to events such as new elements being emitted in a next event, and it can also _receive_ new events such as a next event with an element, which it then emits to its subscribers. This facilitates having an observable that can receive and emit new events during runtime, vs. creating a finite observable.

```
let disposeBag = DisposeBag()

let subject = PublishSubject<String>()

subject
    .subscribe {
        print($0)
    }
    .disposed(by: disposeBag)

// 1
subject.on(.next("Hello"))

// 2
subject.onNext("World")

```

Showing two examples of adding a next event onto the subject…

```
// 1 - passing an Event<String> to the on(_:) operator
// 2 - using the shorthand syntax, which does the same thing (although technically adds one more cpu cycle)

```

This prints out…

```
 Hello
 World

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![evs718](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/evs718/32/81494_2.png) [@evs718](https://forums.kodeco.com/u/evs718)\
**Post date:** [January 22, 2019, 6:22pm UTC](https://forums.kodeco.com/t/subjects-as-observers-not-observables-page-67/58978/4 "2019-01-22T18:22:08Z")

</div>

I understand that. I think you didn’t read my question carefully.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [June 20, 2019, 4:44am UTC](https://forums.kodeco.com/t/subjects-as-observers-not-observables-page-67/58978/5 "2019-06-20T04:44:20Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
