All right. 1
So now that we've successfully added the pod to our project and our project now build successfully, 2
we can actually start making use of the CLTypingLabel module that we just added. 3
So how would we find out what code to write to actually make use of this pod? 4
Well, for that, we'll need to take a look at the documentation under the section Usage Instructions. 5
You can either go back to the GitHub repository's read-me page or you can go back to the page that 6
you saw on CocoaPods. 7
But either way, we have a look at the usage section to see how we can actually use this library. 8
So first, it tells us to change the class of a label from a default UILabel to a CLTypingLabel. 9
So let's go ahead and do that in our Interface Builder as we can see here. 10
So let's open up our Main.storyboard and I'm going to select the label that I want to animate which 11
is this one, of course. 12
And then when we open up the Attributes Inspector, we go over to the Identity Inspector, 13
you can see that by default, it has a class of UILabel. But we're gonna click on the dropdown list and 14
change it to a CLTypingLabel instead. 15
And we're able to see this because we've successfully incorporated the CLTypingLabel module into 16
our project using CocoaPods. 17
So now that we've done step one, let's see what step two involves. 18
Step two tells us to programmatically set a new string to its text property at runtime, 19
and the animations would be triggered automatically. 20
The English is not great here but we're getting a vague idea of what they want us to do. 21
So, essentially, they want us to set the label to a new value when the view loads up. Let's go ahead and 22
comment out all of this code that we've written and change this IBOutlet for our titleLabel which 23
used to have a UILabel as the date type, 24
but now it's actually a CLTypingLabel. 25
And when you put this in, you'll see that it doesn't actually recognize what a CLTypingLabel is. 26
So we have to remember to import the module that we installed using CocoaPods which was called 27
CLTypingLabel. And once that's done and you hit command build, you should see that it now recognizes this 28
data type. And inside of viewDidLoad, instead of all of these lines of code which you can keep if you 29
want just as reference to how we use the for loop in here, but in my case, I'm going to try and keep things 30
clean and I'm just going to delete it. 31
And in our viewDidLoad, in order to trigger the animation, 32
we're going to set the titleLabel.text to equal that string, which in our case was the emoji 33
and the words "FlashChat." 34
So, now by using this pod file, the CLTyping label which contains code that we didn't write, righ? 35
This entire file, CLTyping Label.swift comes from this CocoaPod and it sets up the animation, and it 36
basically does similar to what we got it to do, but perhaps, in a slightly better, more advanced way. 37
And if we go back to our WelcomeViewController, all we have to do was change the class of the label that 38
we want to animate, and then tell it what the text should be that should be typed into it. 39
So, now let's go ahead and hit run and see what happens. 40
And now once we run the app, you'll see that animation occur exactly the same as what we had before, 41
but now we are able to achieve that using just one line of code. 42
So this is a taster into the powers of using third party libraries that you can incorporate into your 43
project. 44
And it's up to you if you want to continue using this pod or if you want to go back to what we had before 45
which is the animation that we generated manually. 46
Now, while you're running this CLTypingLabel, you might notice that you get a warning here talking 47
about something about pies. 48
Sadly, it's not anything that's edible. 49
So what is this all about? 50
Let's go ahead and copy this and paste that warning message into Google to see what we might get. 51
So we're not seeing the exact thing down here so let's try and make this a little bit more specific. 52
We can add some quotes around the word pie and see if we can get some results that are specifically relating 53
this pie thing. 54
And, indeed, we do. We have one right here. 55
So it seems like this pie relates to something called the Position-Independent Executable and it's telling 56
us that the way that we can disable it for our pods, which seems to be the problem we're getting, is to 57
go over to our pods project, build settings, and then search for position, and then change this part to 58
Yes. 59
So let's try that and see if it works. So let's go over to our Pods projects, select it here, and then 60
let's select Pods right here as well, 61
and then we go to Build Settings and we search for "position." And where it says, "Generate 62
Position-Dependent code," 63
we're going to change it 64
to Yes. 65
So, now let's hit run again 66
And you can see that this time, we no longer get that warning. 67
So that's the solution for that warning if you're getting it. And if you're getting a different warning, 68
I also recommend the same system just searching Stack Overflow 69
or Google for the warning message. 70
There's usually somebody else who's encountered it. 71
All right. 72
So at this point, we've seen how to create a pod file, generate an xcworkspace, add a CocoaPod, and successfully 73
use the pod inside our project. 74
There's only one step that I haven't showed you yet and that's removing a pod. 75
In fact, I'm going to remove the CLTypingLabel from my project. 76
That way, you'll learn how to remove a pod if you're no longer interested in using it in your project 77
anymore. 78
Of course, you have the option to leave your code as it is and keep the pod. 79
So you don't have to follow along with me. But I'm going to remove this pod in the completed version 80
of this project and use the code that we wrote ourselves previously. 81
Well, let me restore my titleLabel to a UILabel. And if you want to keep the pod, then you don't have 82
to change your code. 83
You can just watch me as I change my file, and then remove that input statement as well. 84
And the other thing I had to change was to go into our Main.storyboard and change the identity of this 85
back from CLTypingLabel to a UILabel. 86
So once I delete that class, you can see it defaults back to a UILabel. 87
So, now the pod, though, is still right here living in our project, 88
so it means that when we upload our project to the App Store, it's adding maybe a couple of more characters. 89
In this case, it's not particularly bad. It's a really small file. It's really not going to make much of 90
a difference. 91
But if it's a really large module that we've added, you might want to actually remove it from your project. 92
So how do you do that? 93
Well, we go back to the pod file. We remove this particular pod, 94
this line of code, hit save. 95
We close down our project and then we go back into Terminal 96
and we run pod install again. 97
But in this case, we're actually not installing. We're actually uninstalling and you can see that it has 98
removed our CLTypingLabel from our project. 99
Now, if we go back into our FlashChat workspace, you can see that in the pods there are actually no pods 100
in here anymore. 101
We don't have any modules that are being added to our project. 102
But don't delete the pod file because we're going to be using it to add Firebase to our project very 103
soon.