1
00:00:08,120 --> 00:00:13,530
Hey everybody what's going on this is Caleb with Deb's Lopes dot com and welcome to your challenge video

2
00:00:13,560 --> 00:00:15,820
for the subjects section.

3
00:00:15,960 --> 00:00:22,440
We're going to go ahead and give you a challenge here to test your knowledge of subjects published subject

4
00:00:22,440 --> 00:00:26,550
behavior subject replace subject and variable so to do that.

5
00:00:26,550 --> 00:00:31,040
Go ahead and right click on one of the playgrounds and click new playground page.

6
00:00:31,290 --> 00:00:31,890
Name it.

7
00:00:31,890 --> 00:00:34,890
Challenge like so.

8
00:00:34,890 --> 00:00:41,720
Go ahead and select all and delete and you're going to paste in or type in import arke Swift.

9
00:00:41,760 --> 00:00:47,410
Import playground support but at the same time I'm just going to copy and paste it in here.

10
00:00:47,520 --> 00:00:53,580
There are the three lines you have been using and I have some comments here for your challenge for each

11
00:00:53,580 --> 00:00:54,860
of the subjects.

12
00:00:54,990 --> 00:00:57,390
Challenge one published subject.

13
00:00:57,570 --> 00:01:01,610
Remember that only shows elements pushed after the subscription.

14
00:01:01,620 --> 00:01:02,700
Your challenge.

15
00:01:02,700 --> 00:01:04,640
Create a public subject.

16
00:01:04,650 --> 00:01:08,040
Create a publish subject of type string.

17
00:01:08,040 --> 00:01:09,400
Subscribe to it.

18
00:01:09,420 --> 00:01:15,990
Printing the elements in the next closure and push in three movie titles using dot on next.

19
00:01:15,990 --> 00:01:23,220
After subscribing that is Challenge 1 challenge 2 is for behavior subject which remember that shows

20
00:01:23,220 --> 00:01:28,510
the most recently pushed element and everything after the subscription.

21
00:01:28,510 --> 00:01:29,520
Your challenge.

22
00:01:29,520 --> 00:01:32,760
Create a behavior subject of type double.

23
00:01:32,760 --> 00:01:36,760
Set an initial value of zero point zero zero.

24
00:01:36,900 --> 00:01:45,060
Create a variable an R X swift variable called bank balance of type double with an initial value of

25
00:01:45,060 --> 00:01:48,830
your choosing with an R subscribe to it.

26
00:01:49,080 --> 00:01:57,660
Adding the recently pushed item from on next to bank balance got value then pushed in the three amounts

27
00:01:57,960 --> 00:02:03,200
you are sorry then push in 3 separate amounts using on next.

28
00:02:03,210 --> 00:02:06,350
Finally print the bank balance value.

29
00:02:06,780 --> 00:02:13,290
This should show the bank balance with all of the values added up it should show your total amount of

30
00:02:13,290 --> 00:02:16,270
value after adding in 3 amounts.

31
00:02:16,470 --> 00:02:19,680
That is your challenge for behavior subject next.

32
00:02:19,740 --> 00:02:21,180
Replace subject.

33
00:02:21,180 --> 00:02:30,000
Remember a replace subject has a buffer size which is how many elements it can replay and it maintains

34
00:02:30,000 --> 00:02:34,890
a buffer of elements up to that size and will replay them to all future subscribers.

35
00:02:34,890 --> 00:02:41,730
So your challenge with replay subjects is to create a replay subject of type string called Twitter subject

36
00:02:42,210 --> 00:02:45,490
and you're going to set it to have a buffer size of three.

37
00:02:45,810 --> 00:02:49,650
Then subscribe to it and in the on next closure.

38
00:02:49,650 --> 00:02:58,550
Print out followed at and then print out the elements from your reply subject.

39
00:02:58,650 --> 00:03:07,520
Call on next 4 or 5 times on the replace object instance and pass in 4 or 5 individual usernames.

40
00:03:07,770 --> 00:03:16,950
Then create a new variable called new Twitter user and subscribe to Twitter subject in the next closure.

41
00:03:16,950 --> 00:03:20,530
Print out the last three values passed to Twitter subject.

42
00:03:20,550 --> 00:03:23,680
You should be able to do this with a reply subject.

43
00:03:23,850 --> 00:03:28,590
And finally last but certainly not least is variable k remember.

44
00:03:28,590 --> 00:03:35,340
A variable is a wrapper of behavior subject that works similarly to an ordinary swift variable.

45
00:03:35,340 --> 00:03:42,900
Your challenge create an instance of variable called full name and give it a default value of your full

46
00:03:42,900 --> 00:03:43,570
name.

47
00:03:43,890 --> 00:03:49,230
Then convert full name into an observable and subscribe to it.

48
00:03:49,230 --> 00:03:51,030
Inside the annex closure.

49
00:03:51,030 --> 00:03:52,650
Print out the name.

50
00:03:52,650 --> 00:03:58,380
This is your challenge for subjects I wish you luck and I'll see in the next section where we're going

51
00:03:58,380 --> 00:04:00,150
to talk about transformations.

52
00:04:00,150 --> 00:04:06,250
Cool things we can do cool functions we can call to modify data in a functional way.

53
00:04:06,270 --> 00:04:07,190
Very very cool.

54
00:04:07,200 --> 00:04:08,550
Nicely done with this section.

55
00:04:08,550 --> 00:04:11,320
Good luck with the challenge and I'll see in the next section.
