All right. 1
So, now that we're all done with App Store Connect, it's time to head back into Xcode. And first things 2
first, just check to make sure that your Bundle Identifier here is exactly the same one that you used when 3
you created your app ID, 4
and you should be able to see that on your developer.apple.com/account under the App IDs 5
here. 6
So once you've checked that, the next thing is to give that capability to your Xcode project, 7
so having the in InspoQuotes app selected, go into the Capabilities tab, and we're going to switch on 8
in-app purchases which is over here. So we can just toggle the switch to On, and Xcode is going to do some magic 9
behind the scenes. And once all the checkboxes are ticked, then we are ready to go. 10
Now, if at this point, you don't actually see an in-app purchase listing under the capabilities tab, then 11
just quickly check to make sure that when you go to Xcode Preferences, and when you go to Accounts, that 12
you've actually got the same account that you used to set up the App ID as the one that you've got logged 13
in to Xcode. 14
So remember that if it's a paid developer account, the role should say something like Agent and Not User. 15
And, again, also checking under the General tab, make sure that you've got that team which has that same 16
developer account checked as the team for your project. 17
And then coming back to Capabilities and trying to find that in-app purchases. 18
So, if you have multiple Apple IDs, it can get a little bit confusing, 19
so just double check that you are logged in using the same developer Apple ID inside Xcode. 20
So after all of those checks and balances, 21
next step, we are ready to actually write some code. 22
So if you have a look inside Main.storyboard, we've got this table view that is going to be used to 23
list our quotes. 24
And our first job of the day is to show each of these quotes inside a separate cell in our table view. 25
So I'm going to go ahead and, firstly, delete all of these comments that Apple has added inside 26
viewDidLoad. 27
And the next thing is I'm going to edit our Table view data source which is under this pragma MARK here. 28
So we're only going to have one section in our app. So, I'm just going to delete this number of sections 29
data source method. But the next one we will need because this specifies the numberOfRowsInSection. 30
So this all should be very familiar to you given that you've done Todoey and FlashChat. And if you haven't, 31
I strongly recommend that you complete it because table views are a big topic, and I'm not going to go 32
into it in detail here because we've already spoken about it in excruciating detail on the previous 33
tutorials. So I'm just going to go ahead and set this as a challenge for you, given that you have this 34
variable called quotesToShow which is an array that contains six strings, 35
so six quotes. I want you to be able to set up the table view so that you see all six of these quotes 36
inside the table view. 37
Now, just ahead of time, just to mention, some of these are very long. 38
and if they don't fit in the cell, don't worry, we're going to fix that very shortly. 39
But just make sure that you can write some code that makes your table view display six cells and each cell 40
should have one of these quotes. 41
So pause the video now and complete that challenge. 42
All right. So first things first, we know that the number of rows we want is six because we have six quotes. 43
Now, we're not going to put that in by hard coding a number six here because that's very, very inflexible. 44
Instead, we want to give it as a dynamic number by calculating the count of this variable quotesToShow. 45
So instead of returning 0 here, we're going to return quotesToShow.count, and I'm going to delete 46
this warning comment here just to clear things up a little bit. 47
Okay. So, now we're going to have a table view with six blank cells with this line of code. 48
The next thing is to specify what is the data that should go into each of those cells. 49
So I'm going to uncomment this template code that Apple has included in here which is the tableView 50
cellForRowAt indexPath method, 51
and this is the one that actually populates the cells. 52
So, firstly, we create a reusable cell with an identifier. And remember that the Identifier, I gave the prototype 53
cells and check what you gave your prototype cell if you created this from scratch, is over here under 54
the attribute inspector. 55
So I had a QuoteCell and I'm just going to copy and paste that into here as the reuse identifier. 56
So I'm going to create a whole bunch of cells reusing that prototype cell called "QuoteCell," and then 57
I'm going to configure the cell where it tells me to configure the cell. 58
So firstly, I want to change the cell's textLabel.text property to the text that we've got in our 59
quotesToShow variable. 60
So it's going to be equal to quotes to show 61
and I'm going to pull out the item at the index of the current room. 62
So I grab that by using indexPath.row. 63
And because we've done this millions of times, this shouldn't be hard at all. 64
So, now let's go ahead and hit run, and I'm just going to launch that on the simulator because we're not 65
yet testing the in-app purchase part, so it doesn't really matter where we do it. 66
All right. 67
Brilliant. 68
So here's our InspoQuotes app and it's now got six cells each with a quote from over here in this 69
array. 70
Now, as I mentioned before, each cell can only take one line of text at the moment, and it's truncating 71
each of these quotes because they're longer than what can be fitted into each cell. 72
So how can we fix this? 73
Well, normally, when we create a label that we want to have multiple lines of text, then we can set a property 74
called number of lines. And we can do the same with this textLabel because at the end of the day, it's 75
just a label, right? 76
So, if you take a look at UILabel, then you can see it's got all of these attributes or what we call 77
properties, 78
and one of this is number of lines, and it specifies the maximum number of lines 79
label will use to render the text, and you can set it to zero to use as many lines as required. 80
So that's the property that we're going to be changing. 81
So let's close down this documentation, and then we're going to say cell.textLabel.numberOfLines 82
is equal to zero. 83
And now, if we run our app again, everything is taking up as many lines as it needs to in order to display. 84
So for example, this one's taking up three lines, this one's taking up two, 85
and nothing is cut off anymore. 86
So brilliant. 87
The basic functionality of our app is already there and I've kept it really simple in terms of the styling 88
and all of the other fancy flashy parts 89
I've tried to resist adding them in because I just want us to be able to really understand what's going 90
on with the i-app purchasing code. 91
So, hopefully, at this point, all of the code that we've written is very simple and you understand it completely. 92
If you don't, please take a look at the FlashChat module or the Todoey module where we talk about table 93
views and all of these delegate methods in more detail. 94
Ideally, I want you to be really comfortable with all of this code and you should be able to type it 95
blindfolded before we proceed. 96
So if there's any reviewing you need to do, go ahead and do that now. 97
But otherwise, in the next lesson, we're going to get started adding in the in-app purchasing code. 98
So I'll see you over there.