Hey everybody what's going on this is Caleb with Deb's Lopes dot com and welcome to your challenge video
for the subjects section.
We're going to go ahead and give you a challenge here to test your knowledge of subjects published subject
behavior subject replace subject and variable so to do that.
Go ahead and right click on one of the playgrounds and click new playground page.
Name it.
Challenge like so.
Go ahead and select all and delete and you're going to paste in or type in import arke Swift.
Import playground support but at the same time I'm just going to copy and paste it in here.
There are the three lines you have been using and I have some comments here for your challenge for each
of the subjects.
Challenge one published subject.
Remember that only shows elements pushed after the subscription.
Your challenge.
Create a public subject.
Create a publish subject of type string.
Subscribe to it.
Printing the elements in the next closure and push in three movie titles using dot on next.
After subscribing that is Challenge 1 challenge 2 is for behavior subject which remember that shows
the most recently pushed element and everything after the subscription.
Your challenge.
Create a behavior subject of type double.
Set an initial value of zero point zero zero.
Create a variable an R X swift variable called bank balance of type double with an initial value of
your choosing with an R subscribe to it.
Adding the recently pushed item from on next to bank balance got value then pushed in the three amounts
you are sorry then push in 3 separate amounts using on next.
Finally print the bank balance value.
This should show the bank balance with all of the values added up it should show your total amount of
value after adding in 3 amounts.
That is your challenge for behavior subject next.
Replace subject.
Remember a replace subject has a buffer size which is how many elements it can replay and it maintains
a buffer of elements up to that size and will replay them to all future subscribers.
So your challenge with replay subjects is to create a replay subject of type string called Twitter subject
and you're going to set it to have a buffer size of three.
Then subscribe to it and in the on next closure.
Print out followed at and then print out the elements from your reply subject.
Call on next 4 or 5 times on the replace object instance and pass in 4 or 5 individual usernames.
Then create a new variable called new Twitter user and subscribe to Twitter subject in the next closure.
Print out the last three values passed to Twitter subject.
You should be able to do this with a reply subject.
And finally last but certainly not least is variable k remember.
A variable is a wrapper of behavior subject that works similarly to an ordinary swift variable.
Your challenge create an instance of variable called full name and give it a default value of your full
name.
Then convert full name into an observable and subscribe to it.
Inside the annex closure.
Print out the name.
This is your challenge for subjects I wish you luck and I'll see in the next section where we're going
to talk about transformations.
Cool things we can do cool functions we can call to modify data in a functional way.
Very very cool.
Nicely done with this section.
Good luck with the challenge and I'll see in the next section.