1
00:00:06,160 --> 00:00:10,230
Hey everybody what's going on this is Caleb with Deb's Lopes dot com.

2
00:00:10,240 --> 00:00:15,640
And if you remember in the last video we wrote a function that basically prevents are in at purchased

3
00:00:15,640 --> 00:00:18,380
subscriptions from ever being pirated.

4
00:00:18,430 --> 00:00:23,990
It basically uploads the data that saved to your phone compares it against iTunes servers.

5
00:00:24,160 --> 00:00:26,130
If it's good to go we get a response back.

6
00:00:26,140 --> 00:00:31,800
If not we get an error and our app basically returns false saying no.

7
00:00:31,820 --> 00:00:33,430
No that's not a real purchase.

8
00:00:33,430 --> 00:00:39,220
Very very cool stuff in this video we're going to write two functions one that's basically going to

9
00:00:39,220 --> 00:00:44,500
extract the expiration date from the sun data and return it back to us.

10
00:00:44,500 --> 00:00:49,600
We're also going to write a function that will be able to determine whether or not our subscription

11
00:00:49,600 --> 00:00:55,600
is still active or if it expired and to do that we're going to need to make an extension of date so

12
00:00:55,600 --> 00:00:58,930
that we can check to see hey is this less than a certain date.

13
00:00:58,930 --> 00:01:04,270
Is this more than a certain date so that we can basically see hey is our subscription still good to

14
00:01:04,270 --> 00:01:04,510
go.

15
00:01:04,510 --> 00:01:11,430
So pull open your project and let's begin actually by extracting the expiration date from the Jason

16
00:01:11,440 --> 00:01:14,710
data downloaded from our application.

17
00:01:14,830 --> 00:01:20,590
So let's go ahead and beneath our upload receipt function we're going to write a new function called

18
00:01:20,620 --> 00:01:22,700
expiration date from response.

19
00:01:22,720 --> 00:01:29,270
So go ahead and type that phunk expiration date from response.

20
00:01:29,490 --> 00:01:30,320
OK.

21
00:01:30,550 --> 00:01:36,280
Now this function is going to return a date and an optional date because there is a chance that it might

22
00:01:36,280 --> 00:01:37,700
not return anything.

23
00:01:37,720 --> 00:01:44,050
So go ahead and give it some curly brackets and we're going to pass in our Jason response.

24
00:01:44,050 --> 00:01:50,530
Now that should be a capital are a capital R and we need to think most of the time when we're dealing

25
00:01:50,530 --> 00:01:54,330
with Jaison it's cast as a dictionary of string and any.

26
00:01:54,520 --> 00:01:58,850
But we did not do that up here when we have our Jason downloaded.

27
00:01:58,870 --> 00:02:02,890
So we should actually do that first because we're going to pass that into our function.

28
00:02:02,890 --> 00:02:08,000
So let's cast that as a dictionary of string.

29
00:02:08,410 --> 00:02:09,420
And any.

30
00:02:09,430 --> 00:02:13,750
And of course we need to fix that so it says string and that's stirring because that's not a real type

31
00:02:14,090 --> 00:02:14,600
anyway.

32
00:02:14,620 --> 00:02:20,530
So now that this is a dictionary we can pass in this same type into our function so we can type.

33
00:02:20,530 --> 00:02:24,340
Dictionary of string and any escape.

34
00:02:24,370 --> 00:02:25,930
Really really cool.

35
00:02:25,930 --> 00:02:31,720
Now if you remember this is our dictionary that gets passed in k we have lots of information for all

36
00:02:31,720 --> 00:02:33,190
of these different purchases.

37
00:02:33,400 --> 00:02:36,330
And then we also have an expiration date.

38
00:02:36,340 --> 00:02:44,260
You see that right there it says expires date 2017 9 18 2044 20 GMT.

39
00:02:44,260 --> 00:02:48,570
So this is the subscription date when it expires which is pretty cool.

40
00:02:48,610 --> 00:02:53,260
And so we can use that key later to get this value as the date.

41
00:02:53,260 --> 00:02:56,490
So let's go ahead and let's write this function.

42
00:02:56,710 --> 00:03:00,830
Now we're basically going to create an array of receipt info.

43
00:03:01,000 --> 00:03:06,250
And that's going to come from an array within this called receipt info so check it out.

44
00:03:06,310 --> 00:03:13,600
If we look in here we got to look a little bit deeper you'll see that inside this there is an array

45
00:03:13,600 --> 00:03:19,300
called latest receipt info and it comes from the Jason response it's an array which we can tell here

46
00:03:19,690 --> 00:03:22,130
and it's actually an array of dictionaries.

47
00:03:22,210 --> 00:03:22,860
OK.

48
00:03:23,020 --> 00:03:32,530
So what we're going to do is we're going to go ahead and type if let receipt info of type MSRA like

49
00:03:32,540 --> 00:03:39,730
so it's going to be equal to the sun response and we're going to pull out the item that is called latest

50
00:03:39,730 --> 00:03:41,170
receipt info.

51
00:03:45,710 --> 00:03:46,590
Like so.

52
00:03:46,830 --> 00:03:47,500
All right.

53
00:03:47,770 --> 00:03:53,740
And in order to actually cast this as an array we're going to go ahead and cast that optionally as an

54
00:03:53,800 --> 00:03:55,310
NSA right like so.

55
00:03:55,660 --> 00:04:02,800
So assuming that we do get this receipt info re filled we can go ahead and pull out the last receipt

56
00:04:02,830 --> 00:04:07,080
information which if you look here is latest receipt info.

57
00:04:07,090 --> 00:04:09,030
Here's the opening brackets of the array.

58
00:04:09,040 --> 00:04:16,120
And here's the first dictionary second dictionary third fourth fifth sixth and check it out.

59
00:04:16,150 --> 00:04:21,070
OK this is the last dictionary before it goes into the next array pending renewal info.

60
00:04:21,310 --> 00:04:26,410
So we want the last item because that is the latest most up to date information.

61
00:04:26,410 --> 00:04:32,190
So we're going to go ahead and call Let last receipt equals receipt info remember.

62
00:04:32,210 --> 00:04:37,620
That's an X-ray and we can just get the last object by calling dot last object.

63
00:04:37,620 --> 00:04:43,090
OK and that's going to give us the very last object which we know is a dictionary of string and any

64
00:04:43,090 --> 00:04:52,010
object so we can go ahead and just cast that as a dictionary of string and any and I set any object.

65
00:04:52,010 --> 00:04:53,380
But I meant any.

66
00:04:53,450 --> 00:05:00,200
Now what we can do is we can basically pull out the date value here which actually is in the perfect

67
00:05:00,200 --> 00:05:03,060
format for the date type.

68
00:05:03,170 --> 00:05:08,090
But before we do that we're going to actually set up a date formatter so that we can tell it that we

69
00:05:08,090 --> 00:05:13,970
want the date to actually be this exact format with the year month date with the time the time zone

70
00:05:14,000 --> 00:05:15,140
everything.

71
00:05:15,140 --> 00:05:19,570
So let's set up the format first and then we'll set up the instance of date.

72
00:05:19,580 --> 00:05:25,510
So go ahead and type let formatter equals date formatter and instantiate it.

73
00:05:25,550 --> 00:05:29,500
Now we need to set up formatter date format.

74
00:05:29,610 --> 00:05:30,750
There's three tiers there huh.

75
00:05:30,980 --> 00:05:31,840
Formatter.

76
00:05:31,940 --> 00:05:35,090
Date format and you'll see it's of type string.

77
00:05:35,090 --> 00:05:39,150
So in order to set the proper format we need to type it like this.

78
00:05:39,210 --> 00:05:49,400
Why why why why for the years dash capital M M for month Didache lowercase d d for the day then ours

79
00:05:49,430 --> 00:05:51,310
is capitalized.

80
00:05:51,470 --> 00:05:54,820
Minutes is minimized and seconds is also small.

81
00:05:54,980 --> 00:06:01,940
And then at the end Vee-Vee indicates that we want the time zone K so there is our formatted date and

82
00:06:01,940 --> 00:06:11,550
now what we can do is we can create a constant called Let expiration date expiration date of type date

83
00:06:13,040 --> 00:06:20,970
of type date like so equals formatter and then we can call a function upon that.

84
00:06:20,970 --> 00:06:23,440
That's date from string k.

85
00:06:23,460 --> 00:06:28,080
Now we want this string value here which is our expiration date.

86
00:06:28,080 --> 00:06:29,650
Now how are we going to get that.

87
00:06:29,700 --> 00:06:33,670
We can take the last row seat array or the last recy dictionary.

88
00:06:33,720 --> 00:06:39,480
Like so last receipt and we can pull out the value for expires.

89
00:06:39,510 --> 00:06:40,110
Date.

90
00:06:40,110 --> 00:06:40,710
Check it out.

91
00:06:40,710 --> 00:06:41,360
I can type.

92
00:06:41,370 --> 00:06:47,870
Expires date and we can cast this as a string like so.

93
00:06:47,910 --> 00:06:48,400
Whoops.

94
00:06:48,480 --> 00:06:56,130
As String K so we're now creating a date from the expiration date which is conveniently in the same

95
00:06:56,130 --> 00:06:56,550
format.

96
00:06:56,550 --> 00:07:03,660
Thank you Apple and we can cast this as a date like so so that we can basically say hey this needs to

97
00:07:03,660 --> 00:07:05,520
be of type date.

98
00:07:05,520 --> 00:07:09,100
Now we're getting an error saying we're not using this or I guess a warning.

99
00:07:09,390 --> 00:07:10,470
So let's do that.

100
00:07:10,470 --> 00:07:17,390
If the receipt info is good to go we're going to go ahead and return the expiration date.

101
00:07:17,480 --> 00:07:19,050
K that we just generated.

102
00:07:19,080 --> 00:07:26,550
Otherwise we're going to just return nil because this is optional we might not get a return date back

103
00:07:26,790 --> 00:07:27,870
and that's fine.

104
00:07:27,870 --> 00:07:34,050
So if I go ahead and build this you'll notice it'll build it'll run and it will do exactly as we want

105
00:07:34,050 --> 00:07:34,490
it to.

106
00:07:34,500 --> 00:07:42,090
Which is beautiful but we are not yet finished so we're going to go ahead and head back into our upload

107
00:07:42,090 --> 00:07:46,850
receipt function and we're going to call this so that we can set our expiration date.

108
00:07:46,940 --> 00:07:52,980
OK now let's go ahead let's get rid of this print function here and let's just go ahead and say let

109
00:07:53,070 --> 00:08:01,630
new expiration date equals expiration date from response and let's pass in the Jason response Jason.

110
00:08:01,940 --> 00:08:07,680
So as as you might expect this will return a date to us and then we can do something with this expiration

111
00:08:07,680 --> 00:08:08,310
date property.

112
00:08:08,310 --> 00:08:15,350
So let's just print it for now using DEBUG print and we're going to print out new expiration date and

113
00:08:15,350 --> 00:08:25,610
you know what let's actually say new expiration date with space and a comma then we can print out both

114
00:08:25,610 --> 00:08:27,070
in the same debug print.

115
00:08:27,200 --> 00:08:28,010
OK.

116
00:08:28,010 --> 00:08:30,280
Super super cool.

117
00:08:31,130 --> 00:08:34,550
I think we should be good to go if we build this.

118
00:08:34,580 --> 00:08:35,050
Oh you know what.

119
00:08:35,050 --> 00:08:38,790
It's going to say that we need to call cell phone because we're in a closure.

120
00:08:38,930 --> 00:08:44,120
So call self-taught expiration date and let's go build and run this and subscribe and then let's see

121
00:08:44,120 --> 00:08:46,950
if we actually can print out our new expiration date.

122
00:08:47,090 --> 00:08:51,580
So build and run and we should be able to check this out.

123
00:08:55,530 --> 00:08:55,830
All right.

124
00:08:55,840 --> 00:08:57,120
Here we go.

125
00:08:57,490 --> 00:08:58,000
Beautiful.

126
00:08:58,000 --> 00:09:06,040
All right so we see IAP products loaded let's tap on our subscribe button enter our password one two

127
00:09:06,040 --> 00:09:10,610
three exclamation mark press enter.

128
00:09:10,770 --> 00:09:14,950
So remember what we're looking for here is it should print out our new subscription date when we push

129
00:09:14,950 --> 00:09:16,910
subscribe and confirm it.

130
00:09:17,670 --> 00:09:25,930
Let's see what happens UK it says subscription valid purchase was successful.

131
00:09:26,300 --> 00:09:33,890
Interesting so I wonder why we did not get an expiration date to print for us.

132
00:09:35,710 --> 00:09:36,670
Interesting.

133
00:09:37,030 --> 00:09:39,970
So we go through we call oh guys you know what.

134
00:09:40,180 --> 00:09:44,680
I just remembered we we were not calling upload receipt from anywhere.

135
00:09:44,710 --> 00:09:45,880
That is unfortunate.

136
00:09:45,880 --> 00:09:47,260
Let's let's go put it back.

137
00:09:47,260 --> 00:09:51,370
Really quick upload receipt valid.

138
00:09:51,790 --> 00:09:55,750
And you know what we don't actually need to do anything in there because we're just focusing on what's

139
00:09:55,750 --> 00:09:59,230
happening inside the upload receipt function.

140
00:09:59,230 --> 00:10:05,800
And when this loads we should see the expiration date printout which should be about five minutes after

141
00:10:05,800 --> 00:10:07,020
223.

142
00:10:07,390 --> 00:10:09,810
So let's go ahead and push the subscribe button.

143
00:10:11,020 --> 00:10:13,910
New expiration date optional to 2017.

144
00:10:13,930 --> 00:10:17,680
21:27 that's about five minutes after when I subscribe.

145
00:10:17,680 --> 00:10:18,520
So that's amazing.

146
00:10:18,520 --> 00:10:19,530
It's working.

147
00:10:19,540 --> 00:10:21,070
We're getting an expiration date back.

148
00:10:21,070 --> 00:10:25,310
That's five minutes in the future which in the real world would be a whole month.

149
00:10:25,480 --> 00:10:26,250
So that's cool.

150
00:10:26,260 --> 00:10:27,090
That works.

151
00:10:27,160 --> 00:10:28,470
Let's get rid of this.

152
00:10:28,480 --> 00:10:29,430
That's awesome.

153
00:10:29,590 --> 00:10:32,380
And now we can successfully extract our expiration date.

154
00:10:32,380 --> 00:10:36,280
But let's go ahead and let's actually force on rap that so it doesn't come in as optional.

155
00:10:36,280 --> 00:10:38,740
It also silences that warning for us.

156
00:10:38,860 --> 00:10:45,190
But now now that we can actually check to see if our receipt is valid and get our expiration date.

157
00:10:45,190 --> 00:10:51,870
Now is the time for us to basically say hey is is the current date before the expiration date or after.

158
00:10:51,870 --> 00:10:55,270
And that will help us to know hey is our purchase active or not.

159
00:10:55,270 --> 00:11:00,010
So let's go ahead and let's write that function let's stop this from running to free up some memory

160
00:11:00,400 --> 00:11:02,530
and up above upload receipt.

161
00:11:02,710 --> 00:11:04,100
We're going to write a new function.

162
00:11:04,130 --> 00:11:04,670
OK.

163
00:11:04,930 --> 00:11:11,370
So go ahead and type phunk is subscription active OK.

164
00:11:11,770 --> 00:11:18,250
And just like this function we're going to go ahead and basically pass in a boolean and that boolean

165
00:11:18,250 --> 00:11:20,610
is going to say yep it's active or no it's not.

166
00:11:20,620 --> 00:11:25,290
So I'm just going to copy the same completion handler here and paste it in.

167
00:11:25,570 --> 00:11:30,940
So what we're going to do is we are basically going to create a property that will hold the date for

168
00:11:30,940 --> 00:11:37,830
now and then we're going to compare it to the expiration date that gets returned to us from our Jason

169
00:11:37,870 --> 00:11:38,740
call.

170
00:11:38,770 --> 00:11:41,470
So let's go ahead and let's do that by typing.

171
00:11:41,470 --> 00:11:46,160
Let Now date equals date.

172
00:11:46,510 --> 00:11:51,280
And by simply instantiating that we get an instance of date for the exact second that it's instantiated

173
00:11:51,280 --> 00:11:52,260
which is perfect.

174
00:11:52,540 --> 00:11:59,950
So we have the date now but we need a way to basically access the expiration date.

175
00:11:59,950 --> 00:12:05,590
And when we call upload receipt that's great but we should be doing something to save this expiration

176
00:12:05,590 --> 00:12:08,650
date somewhere important like user defaults.

177
00:12:08,650 --> 00:12:10,100
It should be stored there.

178
00:12:10,240 --> 00:12:14,830
So to do that we're going to actually make a quick little function that is going to set the expiration

179
00:12:14,830 --> 00:12:20,240
date into a nice little user defaults Boullion.

180
00:12:20,260 --> 00:12:26,700
So go ahead and call this function phunk set expiration.

181
00:12:27,450 --> 00:12:27,920
OK.

182
00:12:28,120 --> 00:12:34,380
And we're going to set the expiration for a particular date OK with an internal parameter of date of

183
00:12:34,390 --> 00:12:35,360
type date.

184
00:12:35,730 --> 00:12:36,300
OK.

185
00:12:36,520 --> 00:12:43,010
And this function we're going to call user defaults dot standard dot set.

186
00:12:43,220 --> 00:12:43,850
OK.

187
00:12:44,170 --> 00:12:49,570
And we're going to set value of any K for a particular key of type string.

188
00:12:49,570 --> 00:12:57,400
Now the value is the date coming in right and we're setting it with the key expiration date with only

189
00:12:57,400 --> 00:12:58,450
one t.

190
00:12:58,470 --> 00:13:02,260
Now this key will help us to access this from user defaults later on.

191
00:13:02,260 --> 00:13:06,480
But for now this function will let us save it and keep it there.

192
00:13:06,490 --> 00:13:09,720
So instead of just printing the expiration date.

193
00:13:09,730 --> 00:13:16,740
Now let's go ahead and call self set expiration for date new expiration date.

194
00:13:16,930 --> 00:13:17,640
OK.

195
00:13:17,950 --> 00:13:18,610
Really cool.

196
00:13:18,610 --> 00:13:23,200
And you know what let's go ahead and force on wrap it there so that we save the value not the optional

197
00:13:23,200 --> 00:13:24,040
value.

198
00:13:24,200 --> 00:13:28,760
And now we will be able to actually save our date which is beautiful.

199
00:13:28,870 --> 00:13:32,570
Now that's great to save it in user defaults.

200
00:13:32,680 --> 00:13:39,940
But I wish we had a property in this in this Singleton that we can basically access at any time which

201
00:13:39,940 --> 00:13:42,900
we can do if we go ahead and go up to the top.

202
00:13:42,940 --> 00:13:47,960
We created 1 in the starter project for the Boullion non consumable purchase was made.

203
00:13:47,980 --> 00:13:57,940
So right above that we can type var expiration date expiration date equals user defaults dot standard

204
00:13:58,240 --> 00:14:03,570
dot value for key and the path or the key.

205
00:14:03,580 --> 00:14:06,230
I mean is expiration date.

206
00:14:06,430 --> 00:14:06,990
All right.

207
00:14:07,000 --> 00:14:07,750
And you know what.

208
00:14:07,870 --> 00:14:11,690
Since that's just a value I'm going to actually cast it.

209
00:14:11,920 --> 00:14:17,080
Let's forecast that as a date because we know it's going to come in as date if it'll let us forecast

210
00:14:17,080 --> 00:14:18,020
that.

211
00:14:18,700 --> 00:14:19,390
Okay perfect.

212
00:14:19,390 --> 00:14:20,660
That's really cool.

213
00:14:20,830 --> 00:14:21,860
That will work.

214
00:14:21,880 --> 00:14:32,140
And now what we can do is we can basically say you know if the now date is before or less than the expiration

215
00:14:32,140 --> 00:14:38,110
date we're good otherwise we're not okay that's how we're going to basically determine if our subscription

216
00:14:38,470 --> 00:14:40,150
is active or not.

217
00:14:40,150 --> 00:14:45,670
Now the problem with what we're doing here is that the date subclassed and all of the fancy date stuff

218
00:14:45,670 --> 00:14:51,220
does not really have a function that can that can compare dates in this way so easily.

219
00:14:51,220 --> 00:14:56,320
So what we're actually going to do is to create an extension of date write our own custom function and

220
00:14:56,320 --> 00:14:58,730
call it comparing the two dates.

221
00:14:58,750 --> 00:15:04,270
So go ahead and right click on food Zyla create a new group and call it extension's.

222
00:15:04,600 --> 00:15:07,780
Right click on the extensions folder and create a new file.

223
00:15:07,900 --> 00:15:08,590
OK click.

224
00:15:08,590 --> 00:15:09,990
Swift file.

225
00:15:10,420 --> 00:15:15,360
And then we're going to go ahead and just call this date XTi.

226
00:15:15,390 --> 00:15:20,450
OK so now we're going to do is we're going to go ahead and create an extension of date by typing extension

227
00:15:21,020 --> 00:15:22,520
date.

228
00:15:22,730 --> 00:15:27,200
And now any functions that we write in here it can be called upon any instance of date.

229
00:15:27,210 --> 00:15:35,000
And so let's do that by typing phunk is less than.

230
00:15:35,210 --> 00:15:42,460
And we're going to be able to pass in a date and then use that to compare against the current date.

231
00:15:42,490 --> 00:15:43,360
OK.

232
00:15:43,360 --> 00:15:50,830
Now go ahead and just create a property here let's just say past date of type date and we're going to

233
00:15:50,830 --> 00:15:57,400
basically say if self meaning whatever instance of date let's say that I made an instance of the date

234
00:15:57,400 --> 00:16:07,330
for today like you know the now date constantly created if self time interval since and look at what

235
00:16:07,330 --> 00:16:12,320
it does it returns the interval between the receiver and another given date.

236
00:16:12,460 --> 00:16:20,740
So now and then if we can get the difference we get the value of how long it will take basically to

237
00:16:20,740 --> 00:16:22,150
get to that point.

238
00:16:22,150 --> 00:16:33,550
So if the time interval since the past date well past date sounds like in the past let's just say date.

239
00:16:33,550 --> 00:16:35,470
How about that.

240
00:16:35,470 --> 00:16:36,920
That makes a little more sense.

241
00:16:36,940 --> 00:16:47,540
So if the of if the if the instance of date that this is called on we're going to say how far is it

242
00:16:47,600 --> 00:16:51,800
until the actual subscription expiration date.

243
00:16:51,890 --> 00:17:02,630
Ok if that is less than the date we pass in time interval since now meaning the difference between the

244
00:17:02,630 --> 00:17:09,560
date value and right now then what we're going to do is we're going to go ahead and return true.

245
00:17:09,920 --> 00:17:10,270
Okay.

246
00:17:10,280 --> 00:17:13,770
And you know what we need to actually return a boolean here if we're going to do that.

247
00:17:14,510 --> 00:17:14,970
Okay.

248
00:17:14,990 --> 00:17:15,740
Otherwise

249
00:17:18,530 --> 00:17:20,420
we're going to return false.

250
00:17:20,420 --> 00:17:25,130
Now what this function is basically going to do is it's going to let us say hey if the current date

251
00:17:25,190 --> 00:17:28,640
is less then the subscription date then it's valid.

252
00:17:28,790 --> 00:17:31,080
If it's not then it's going to return false.

253
00:17:31,100 --> 00:17:37,850
So let's go back into our IAP service and what we can do is we can take that property we just saved

254
00:17:37,910 --> 00:17:39,020
the expiration date.

255
00:17:39,020 --> 00:17:41,260
We're pulling it from user defaults.

256
00:17:41,330 --> 00:17:46,850
What we can do is we can basically say hey if there's an expiration date if if one is saved because

257
00:17:47,000 --> 00:17:49,050
the odds are one might not be saved.

258
00:17:49,100 --> 00:17:49,710
OK.

259
00:17:49,880 --> 00:17:57,530
You know a new subscriber if one is subscribed if a date is saved we can say hey if Now if the now date

260
00:17:57,740 --> 00:18:03,500
is less then the expiration date we can return true to our completion handler meaning subscription still

261
00:18:03,500 --> 00:18:04,480
active man.

262
00:18:04,610 --> 00:18:06,180
If not we can return false.

263
00:18:06,200 --> 00:18:11,720
So let's go ahead and let's use guard let so that we can safely create a constant for the expiration

264
00:18:11,720 --> 00:18:13,070
date in case there's not one.

265
00:18:13,070 --> 00:18:15,400
So go ahead and type guard.

266
00:18:15,470 --> 00:18:20,630
Let expiration date equals expiration date.

267
00:18:20,630 --> 00:18:29,270
The one we have saved up above and we can say else return cake because if we do not have one we'll just

268
00:18:29,270 --> 00:18:29,720
return.

269
00:18:29,720 --> 00:18:32,820
Get out of the function and save us from crashing.

270
00:18:33,140 --> 00:18:40,880
What we can do is we can say hey if the now date is less then remember that's our extension.

271
00:18:40,880 --> 00:18:44,070
If it's less then the expiration date.

272
00:18:44,480 --> 00:18:45,670
Check it out.

273
00:18:45,710 --> 00:18:50,510
We can go ahead and say hey completion is going to be true.

274
00:18:50,510 --> 00:18:56,900
Otherwise if it's not less then that means we've already gone past our expiration date else completion

275
00:18:56,900 --> 00:18:58,500
handler is false.

276
00:18:58,510 --> 00:18:58,830
OK.

277
00:18:58,850 --> 00:18:59,660
So that's pretty cool.

278
00:18:59,660 --> 00:19:04,520
Now we're getting an error here at saying needs to be optional cannot be of type date.

279
00:19:04,520 --> 00:19:07,900
But the reason for that is because we're force unwrapping it as date.

280
00:19:07,910 --> 00:19:13,580
Let's go ahead and optionally unwrap it there as a date and you'll see that air will go away.

281
00:19:13,580 --> 00:19:15,420
Our function will work.

282
00:19:15,440 --> 00:19:18,170
And this is super super cool guys.

283
00:19:18,380 --> 00:19:19,640
I think we should try this.

284
00:19:19,640 --> 00:19:27,410
I think that we should go ahead and see if this works to call our is subscription active function but

285
00:19:27,410 --> 00:19:29,260
we need to think of a way we can do it.

286
00:19:29,270 --> 00:19:31,760
And you know what let's actually figure that out in the next video.

287
00:19:31,760 --> 00:19:32,990
I have just the thing.

288
00:19:32,990 --> 00:19:36,180
So let's head over there and I'll see in the next video.
