TRANSCRIPT 🔗
1
00:00:03,419 --> 00:00:05,620
Leo Dion (host): Welcome to
another episode of empower apps.
2
00:00:05,690 --> 00:00:07,409
I'm your host Leo Dan today.
3
00:00:07,450 --> 00:00:09,360
I'm joined by Brandon Williams.
4
00:00:09,370 --> 00:00:11,339
Brandon, thank you so
much for coming on.
5
00:00:12,000 --> 00:00:12,250
Brandon Williams (guest): Yeah.
6
00:00:12,260 --> 00:00:13,050
Thanks for having me.
7
00:00:13,520 --> 00:00:16,089
Leo Dion (host): I know a lot
of people are fan, fans of your
8
00:00:16,089 --> 00:00:18,080
work point free with Steven.
9
00:00:18,619 --> 00:00:21,690
But I'll let you go ahead and introduce
yourself before we get started.
10
00:00:22,140 --> 00:00:22,440
So
11
00:00:22,700 --> 00:00:23,570
Brandon Williams (guest): Yeah, sure.
12
00:00:23,600 --> 00:00:24,580
Yeah, I'm Brandon.
13
00:00:24,590 --> 00:00:29,129
I do run a site called Point
Free with Stephen Sellis.
14
00:00:29,530 --> 00:00:33,509
It's a video series, educational
video series, kind of concentrating
15
00:00:33,509 --> 00:00:38,890
some of the more complex and advanced
aspects of the Swift language and we
16
00:00:38,890 --> 00:00:42,139
do a lot of open source work we'll
probably be talking about at least
17
00:00:42,140 --> 00:00:45,400
one of the libraries today, but
but yeah that's the general thing.
18
00:00:46,140 --> 00:00:49,780
Leo Dion (host): you've got a big
talk coming up at Swift Toronto
19
00:00:49,870 --> 00:00:54,490
which is going to be awesome, it is
about controlling your dependencies,
20
00:00:54,520 --> 00:00:55,970
not letting them control you.
21
00:00:56,420 --> 00:00:59,990
And now initially when I saw that
I was like, Oh, it's going to be
22
00:01:00,140 --> 00:01:03,679
like about swift package manager,
Cocoa pods or something like that.
23
00:01:04,190 --> 00:01:07,719
But in fact you have a broader
and probably more correct
24
00:01:07,749 --> 00:01:09,700
definition of what a dependency is.
25
00:01:10,210 --> 00:01:12,560
Do you want to explain
exactly what that means?
26
00:01:13,160 --> 00:01:13,420
Brandon Williams (guest): Sure.
27
00:01:13,420 --> 00:01:17,030
Yeah, I think anything you probably
add into your SPM package of course,
28
00:01:17,050 --> 00:01:19,930
you would call that dependency because
you're bringing in someone else's code.
29
00:01:20,149 --> 00:01:22,800
But I think the yeah, the definition
could be a little bit broader.
30
00:01:22,800 --> 00:01:26,419
And it's really just when you have
to touch API's and other people's
31
00:01:26,420 --> 00:01:28,749
code that you can't control.
32
00:01:28,935 --> 00:01:31,205
And so that would even
include Apple's code, right?
33
00:01:31,205 --> 00:01:34,665
You don't ever add a dependency
in SPM to get access to core
34
00:01:34,665 --> 00:01:35,955
location or anything like that.
35
00:01:35,965 --> 00:01:39,525
That's, it's just kind of ambiently
there ready for you, but that still
36
00:01:39,555 --> 00:01:43,975
is a dependency because whenever
you make a direct call to some core
37
00:01:43,975 --> 00:01:48,015
location API, you're touching code
that you can't possibly control.
38
00:01:48,225 --> 00:01:51,145
And that puts you in kind of a
compromised position when it comes to
39
00:01:51,155 --> 00:01:54,555
running your code and certain situations
that you would want to, but it turns
40
00:01:54,555 --> 00:01:57,564
out you can't because you just, you
don't have control over that code.
41
00:01:57,925 --> 00:02:00,235
Leo Dion (host): And I think that's
the key point, is that this is pieces
42
00:02:00,235 --> 00:02:01,845
of your code you have no control over.
43
00:02:02,215 --> 00:02:05,595
So like you, you talk about core
location and how that works.
44
00:02:06,035 --> 00:02:08,765
Anything networking,
obviously, anything database.
45
00:02:09,195 --> 00:02:09,505
Brandon Williams (guest): Yeah
46
00:02:10,075 --> 00:02:12,704
Leo Dion (host): even sleep
timers and that kind of
47
00:02:12,705 --> 00:02:15,895
Brandon Williams (guest): timers,
user defaults it could be it's, and
48
00:02:15,895 --> 00:02:19,545
I'll say even date generators and
UUID generators, all those things
49
00:02:19,545 --> 00:02:24,885
that just can extract out like
new information out of the void.
50
00:02:24,885 --> 00:02:27,725
Like when you ask for a new
date, you get the current
51
00:02:27,735 --> 00:02:29,725
time, all that kind of stuff.
52
00:02:29,935 --> 00:02:30,205
Yeah.
53
00:02:30,205 --> 00:02:32,715
Needs, it can wreak
havoc in a code base.
54
00:02:33,565 --> 00:02:36,515
Leo Dion (host): Yeah, I like, that was
the part that I found interesting is
55
00:02:36,515 --> 00:02:39,645
when you talked about UUIDs and dates.
56
00:02:39,985 --> 00:02:43,005
Because I don't think of those
as you can't control them.
57
00:02:43,690 --> 00:02:47,060
But in a sense, you do get a wild
value every time you call them.
58
00:02:47,705 --> 00:02:47,995
Brandon Williams (guest): Right.
59
00:02:47,995 --> 00:02:48,145
Right.
60
00:02:48,145 --> 00:02:48,445
Yeah.
61
00:02:48,445 --> 00:02:54,085
Every time you do like capital UUID,
open, close, print, that initializer is
62
00:02:54,095 --> 00:02:55,895
you just get a whole new value of it.
63
00:02:55,895 --> 00:02:57,005
And you may not think it's.
64
00:02:57,530 --> 00:02:59,190
that big of a deal to get
a new value out of it.
65
00:02:59,190 --> 00:03:03,390
That is the point of it, but it can
cause trouble for that one in particular
66
00:03:03,390 --> 00:03:06,530
can cause trouble with testing
because you may want to assert that
67
00:03:06,530 --> 00:03:08,630
some model equals some other model.
68
00:03:08,760 --> 00:03:11,680
But if you can't predict the ID that
was generated in the first model,
69
00:03:11,680 --> 00:03:16,165
then you've got No way of comparing
those two as two like models together.
70
00:03:16,165 --> 00:03:19,065
You can't have to compare
Load full transcript
them
field by field rather, and then
71
00:03:19,065 --> 00:03:21,765
it's on you to remember when you
add a new field, you got to go add
72
00:03:21,765 --> 00:03:23,275
a new assertion for that new field.
73
00:03:23,535 --> 00:03:26,455
Whereas if you just asserted that
this model equals this model, it would
74
00:03:26,455 --> 00:03:28,464
take all of care of all of it for you.
75
00:03:28,720 --> 00:03:30,660
Leo Dion (host): Yeah, so let's
jump into testing, because I
76
00:03:30,700 --> 00:03:31,860
think that's the big thing.
77
00:03:32,030 --> 00:03:35,450
There's two things you mentioned
Xcode previews and testing is
78
00:03:35,450 --> 00:03:37,220
where you run into these issues.
79
00:03:37,760 --> 00:03:40,579
You want to go over some let's start
with the testing part since you
80
00:03:40,579 --> 00:03:43,799
just mentioned that, what are the
particular issues that people will run
81
00:03:43,799 --> 00:03:48,479
into when it comes to testing these
kind of uncontrolled dependencies?
82
00:03:48,784 --> 00:03:51,954
Brandon Williams (guest): Yeah it
just so if you start sprinkling in
83
00:03:52,164 --> 00:03:57,264
code like access to location managers,
network request into your code, you
84
00:03:57,814 --> 00:04:01,164
it becomes very difficult, if not
impossible to unit test and unit
85
00:04:01,164 --> 00:04:04,064
testing is a very particular way
of running your code in which you.
86
00:04:04,364 --> 00:04:07,994
Kind of put it in a little sandboxed
isolated execution environment
87
00:04:07,994 --> 00:04:11,234
where you need to be able to run
it without having spun up a view
88
00:04:11,254 --> 00:04:13,314
controller or spun up a SwiftUI view.
89
00:04:13,314 --> 00:04:16,124
It needs to be just able
to run all on its own.
90
00:04:16,544 --> 00:04:19,874
And if you reach out to a
network request you have no
91
00:04:19,874 --> 00:04:22,654
way of predicting what is the
data that's going to come back.
92
00:04:22,664 --> 00:04:25,554
You know, if you reach out
to some API that loads like
93
00:04:25,554 --> 00:04:28,464
Mastodon posts, you don't know.
94
00:04:28,654 --> 00:04:29,564
what's going to come back.
95
00:04:29,574 --> 00:04:32,704
And so you have no way of then
testing how that data flows
96
00:04:32,704 --> 00:04:33,824
through your application.
97
00:04:34,154 --> 00:04:36,874
And the point of controlling
the dependency so that you can
98
00:04:36,874 --> 00:04:38,694
predict what is coming back.
99
00:04:38,804 --> 00:04:42,714
It's not so that you can exercise what
the Mastodon API is doing where we just
100
00:04:42,864 --> 00:04:45,834
have no choice but really to assume that
they're going to do the right thing.
101
00:04:46,084 --> 00:04:47,684
And they'll send us back some posts.
102
00:04:47,694 --> 00:04:48,644
What we want to test is.
103
00:04:48,919 --> 00:04:51,849
When the post come back, how
does that flow through our logic?
104
00:04:51,859 --> 00:04:54,919
Where does that data get
filtered and transformed and
105
00:04:54,919 --> 00:04:56,649
put into everything else?
106
00:04:56,659 --> 00:04:57,509
That's what we want to test.
107
00:04:57,509 --> 00:05:01,819
And you can't do that unless you in
some way control that dependency.
108
00:05:02,459 --> 00:05:05,229
Leo Dion (host): Yeah, I think
that's one of the biggest challenges
109
00:05:05,259 --> 00:05:08,009
I feel like people get when they
start unit testing is they're like
110
00:05:08,369 --> 00:05:09,909
how do I do this with the database?
111
00:05:09,999 --> 00:05:11,209
How do I do this with the network?
112
00:05:11,209 --> 00:05:15,049
It's no, like you're not testing
that the database works or
113
00:05:15,049 --> 00:05:16,109
the networking call works.
114
00:05:16,109 --> 00:05:19,119
You're testing your behavior
based on what you get back.
115
00:05:19,569 --> 00:05:20,419
Brandon Williams (guest):
Yeah, it's tricky.
116
00:05:20,419 --> 00:05:23,409
I think, and a lot of people
stumble on that when they're first
117
00:05:23,409 --> 00:05:26,669
learning about testing and it
can, I think it can set you back.
118
00:05:26,669 --> 00:05:27,939
If you look at it, you're like, wait.
119
00:05:28,379 --> 00:05:31,029
I don't want to test,
you know, Apple's APIs.
120
00:05:31,029 --> 00:05:32,409
I don't want to test core location.
121
00:05:32,409 --> 00:05:33,399
So why would I do this?
122
00:05:33,399 --> 00:05:36,239
And that's kind of not the, that's
the point is that to not test those
123
00:05:36,239 --> 00:05:40,449
things and to get just to pretend that
their API worked the way you expect
124
00:05:40,529 --> 00:05:42,039
and it fed data into your thing.
125
00:05:42,389 --> 00:05:43,380
But it's very tricky.
126
00:05:43,655 --> 00:05:46,445
Leo Dion (host): So before we
get into solutions what let's
127
00:05:46,445 --> 00:05:47,615
talk about Xcode previews.
128
00:05:47,625 --> 00:05:53,295
What are some things that Xcode previews
like, what are some challenges that
129
00:05:53,295 --> 00:05:57,115
Xcode previews gives you different
from just what unit tests do.
130
00:05:57,715 --> 00:06:00,145
Brandon Williams (guest): Yeah
there are so well, there's a couple
131
00:06:00,145 --> 00:06:05,645
of aspects to this for the first
part, it's the more you compile in a
132
00:06:05,645 --> 00:06:09,625
particular project, the bigger chance
you have of just breaking previews.
133
00:06:09,805 --> 00:06:12,405
And so your first step to Improving
the stability previews is kind of
134
00:06:12,405 --> 00:06:15,165
break up your project into lots
of little modules and that can
135
00:06:15,165 --> 00:06:16,375
greatly improve the stability.
136
00:06:16,405 --> 00:06:20,045
So once you've done that, you've got
a far more stable preview, but then
137
00:06:20,225 --> 00:06:25,775
there are a lot of APIs out there that
will just completely break the preview.
138
00:06:25,775 --> 00:06:28,985
And in
a couple of ways first of all,
like things like a core location,
139
00:06:29,005 --> 00:06:30,675
if you just indiscriminately.
140
00:06:31,060 --> 00:06:36,030
Request permissions for location and
you use that check to kind of block
141
00:06:36,070 --> 00:06:39,830
other things happening in your UI, what
will happen is you'll load the preview.
142
00:06:40,020 --> 00:06:43,850
You'll never see that little iOS
alert saying, you know, do you
143
00:06:43,850 --> 00:06:46,000
want to get permission because
previews do not support that.
144
00:06:46,000 --> 00:06:46,760
And I don't know if that's.
145
00:06:47,095 --> 00:06:50,675
considered a bug in previews, or if it's
just how previews are expected to work.
146
00:06:50,675 --> 00:06:53,935
But you'll never get that little
permission box, and therefore you'll
147
00:06:53,935 --> 00:06:57,425
just never be able to see in your
preview what happens afterwards.
148
00:06:57,785 --> 00:07:01,345
And so that just completely ruins that
kind of iterative cycle on previews.
149
00:07:01,345 --> 00:07:02,715
You're just not allowed to use it.
150
00:07:03,135 --> 00:07:06,645
And then there's other kinds of things
that just will completely crash the
151
00:07:06,645 --> 00:07:11,455
preview, because some APIs require
That you have a little info P list in
152
00:07:11,455 --> 00:07:14,915
your application that describes why
it is you want to access that thing.
153
00:07:14,915 --> 00:07:17,675
And that's like anytime you
access the microphone, the
154
00:07:17,675 --> 00:07:20,115
contacts, even the core location.
155
00:07:20,385 --> 00:07:22,895
But for some reason, core location
doesn't do this, but other ones do.
156
00:07:22,915 --> 00:07:27,035
They will just simply crash your
app if you try to access the API
157
00:07:27,075 --> 00:07:28,865
without that info P list being there.
158
00:07:29,185 --> 00:07:32,445
And so then what happens is you've
got your preview and it just crashes.
159
00:07:32,445 --> 00:07:34,205
You just, you literally can't run it.
160
00:07:34,585 --> 00:07:35,995
And that's honestly just the beginning.
161
00:07:35,995 --> 00:07:39,505
Like these dependencies a lot of them
will just make your previews very
162
00:07:39,505 --> 00:07:44,555
flaky, not stable, make them inert and
functionless or just completely crash.
163
00:07:45,490 --> 00:07:48,730
Leo Dion (host): So now we're going to
add it into some like terminology fun
164
00:07:48,730 --> 00:07:52,610
here, but the way I've done it, and
it's kind of what you kind of get at.
165
00:07:52,955 --> 00:07:57,405
And your talk is using mocks, but I
might be using the wrong term because
166
00:07:57,405 --> 00:08:01,335
there's 50 different definitions
of mock stubs and blah, blah, blah.
167
00:08:01,585 --> 00:08:04,235
But that's essentially what I
ended up doing is creating mocks.
168
00:08:04,255 --> 00:08:07,575
And in some cases I'll create a
special mock for previews or a
169
00:08:07,575 --> 00:08:11,685
special mock for unit tests, but
it does whatever you tell it to do
170
00:08:11,715 --> 00:08:15,635
essentially where it's like, Oh here,
in this case, give me this lat long.
171
00:08:15,980 --> 00:08:19,760
Just hard code it essentially, or,
you know, with networking, like
172
00:08:19,760 --> 00:08:21,620
here, give, throw this error in it.
173
00:08:21,680 --> 00:08:25,610
And that seems like basically
what it comes down to as a
174
00:08:25,610 --> 00:08:26,980
solution for this kind of thing.
175
00:08:26,980 --> 00:08:28,130
Is that correct?
176
00:08:28,475 --> 00:08:28,685
Brandon Williams (guest): Yeah.
177
00:08:28,685 --> 00:08:32,535
That's the entire solution is rather
than reaching out directly to like
178
00:08:32,535 --> 00:08:37,405
core location or URL session to
load data, you put a little, a
179
00:08:37,405 --> 00:08:39,085
lightweight interface in front of it.
180
00:08:39,355 --> 00:08:42,285
And then in previews and
tasks, you can swap out.
181
00:08:42,720 --> 00:08:46,580
A implementation to put into your
feature so that it just immediately
182
00:08:46,580 --> 00:08:48,090
returns you some data and I agree.
183
00:08:48,090 --> 00:08:51,610
I don't know whether that's a mock
or a stub or a fake or a spy or
184
00:08:51,610 --> 00:08:53,620
whatever I like that zoo of terms.
185
00:08:53,620 --> 00:08:56,210
It doesn't really matter, because all
that really matters that we have an
186
00:08:56,210 --> 00:08:59,860
interface and at runtime we want to
swap it in with something that does
187
00:08:59,860 --> 00:09:01,000
something a little bit different.
188
00:09:01,010 --> 00:09:03,240
Like when you run in the
simulator on your device, you
189
00:09:03,240 --> 00:09:04,290
want to use the real thing.
190
00:09:04,300 --> 00:09:05,870
You want to use core location.
191
00:09:05,870 --> 00:09:09,370
You want to access those APIs,
but in almost all other cases
192
00:09:09,370 --> 00:09:10,650
you want to put in something.
193
00:09:11,120 --> 00:09:14,570
Just simpler, something just, you say,
give me the current location, and it
194
00:09:14,570 --> 00:09:18,090
just hands you back immediately some
lat long, and then your preview will
195
00:09:18,090 --> 00:09:19,800
hum right along, and it'll be good.
196
00:09:20,450 --> 00:09:23,110
Leo Dion (host): So in your talk,
you talk about protocols is typically
197
00:09:23,110 --> 00:09:26,580
the way I've done it, but you
had some reservations about that.
198
00:09:26,580 --> 00:09:28,020
You want to explain what those are?
199
00:09:28,450 --> 00:09:30,970
Brandon Williams (guest): Yeah alright,
this is like a long, I mean, Steve and
200
00:09:30,970 --> 00:09:34,690
I have been talking about this thing
for many years, and protocols are, yeah,
201
00:09:34,690 --> 00:09:38,110
certainly the most popular, the de facto
way of putting interface in front of
202
00:09:38,150 --> 00:09:39,480
something, but it's
not the only way.
203
00:09:39,700 --> 00:09:43,280
There is this slightly different
way in which you can use a struct
204
00:09:43,580 --> 00:09:45,600
that has closure properties.
205
00:09:45,955 --> 00:09:50,175
And I can substitute in for
a protocol for the most part.
206
00:09:50,205 --> 00:09:54,435
And in particular, when it comes to
controlling dependencies protocols, you
207
00:09:54,455 --> 00:09:57,245
typically just got two implementations.
208
00:09:57,245 --> 00:09:59,985
You've got the live one, and then
you got kind of like a mock one.
209
00:10:00,225 --> 00:10:03,135
And in such situations, the protocols
may be a little too high powered,
210
00:10:03,135 --> 00:10:07,725
although Protocols have gotten a lot of
features recently that make this a lot
211
00:10:07,725 --> 00:10:13,045
nicer you know, Rewind Early Swift the
Struct version was a lot more enticing.
212
00:10:13,045 --> 00:10:16,515
Now protocols do satisfy a lot of
things that allow this to be easy.
213
00:10:16,515 --> 00:10:19,975
But anyway, so if you use the Struct
interface, it allows you to do some fun
214
00:10:19,985 --> 00:10:25,295
things, like you get the ability to kind
of hot swap out one single endpoint in
215
00:10:25,295 --> 00:10:26,855
the dependency for new functionality.
216
00:10:26,855 --> 00:10:27,695
So you could.
217
00:10:28,065 --> 00:10:33,425
You could have a mostly live
dependency that accesses the true API
218
00:10:33,465 --> 00:10:37,595
endpoints but you just swap one of
the endpoints to do something with
219
00:10:37,785 --> 00:10:41,435
a mock or something, you know, more
custom and that can be really powerful
220
00:10:41,435 --> 00:10:45,625
for really sculpting very specific
situations that you want to test.
221
00:10:45,960 --> 00:10:46,210
Leo Dion (host): okay.
222
00:10:46,220 --> 00:10:47,000
Interesting.
223
00:10:47,000 --> 00:10:50,300
What were the things that you were
going to mention with protocols that
224
00:10:50,300 --> 00:10:51,980
are new, that make it more enticing?
225
00:10:52,615 --> 00:10:55,065
Brandon Williams (guest): Oh,
just the fact that we have more of
226
00:10:55,075 --> 00:10:58,745
the existential machinery and the
protocol with associated types.
227
00:10:58,745 --> 00:10:59,325
That stuff,
228
00:10:59,375 --> 00:11:00,764
Leo Dion (host): primary
associated types, yada.
229
00:11:00,764 --> 00:11:01,134
Okay.
230
00:11:01,284 --> 00:11:03,364
Brandon Williams (guest): All that
stuff makes it so that it is far
231
00:11:03,364 --> 00:11:05,284
less painful to deal with protocols.
232
00:11:05,284 --> 00:11:08,964
Like prior to swift five, I don't
know if that was six or seven.
233
00:11:09,264 --> 00:11:12,374
It was to me, it was an absolute
no brainer that you would use a
234
00:11:12,374 --> 00:11:13,914
strike for these things afterwards.
235
00:11:13,914 --> 00:11:17,344
I'm just like, whatever suits your
fancy, just, you know, go for it.
236
00:11:17,644
--> 00:11:20,674
But I do think there are pros
to the stroke, the struck style.
237
00:11:20,674 --> 00:11:23,564
But yeah, it's if you're used to the
protocols and go for the protocols.
238
00:11:23,744 --> 00:11:27,294
Leo Dion (host): Yeah, I think I do
protocols probably like 80% of the time
239
00:11:27,294 --> 00:11:30,864
and then the other 20% if I can throw
in a closure and just do it that way.
240
00:11:31,304 --> 00:11:32,474
I'll do that as well.
241
00:11:32,644 --> 00:11:35,904
If it's simple enough, it's just when
I end up having other dependencies
242
00:11:35,904 --> 00:11:39,004
or when I have the protocol needs
to do a little bit more complicated
243
00:11:39,004 --> 00:11:41,874
stuff, it's yeah, I'll probably end
up Do you need to do a protocol?
244
00:11:41,994 --> 00:11:44,024
Brandon Williams (guest): the
more complicated the protocol,
245
00:11:44,034 --> 00:11:48,334
the more it pushes towards like
protocol being the way to go.
246
00:11:48,514 --> 00:11:52,944
But I also say that Apple's, some of
their recent APIs have even skewed
247
00:11:52,964 --> 00:11:56,524
protocols in favor of just simple,
like basically bags of closures.
248
00:11:56,524 --> 00:12:00,594
Like some of their collection view,
like data source stuff, historically
249
00:12:00,594 --> 00:12:01,624
that would have all been protocols.
250
00:12:01,624 --> 00:12:02,764
You would have made your object or
251
00:12:03,064 --> 00:12:05,184
Leo Dion (host): Delegates,
probably delegates,
252
00:12:05,449 --> 00:12:05,989
Brandon Williams (guest): yeah, Delica.
253
00:12:05,989 --> 00:12:09,639
So all that stuff has like slowly
been going more towards Closure Base.
254
00:12:09,649 --> 00:12:12,929
So I mean, it's, yeah there's
nothing all that strange about it,
255
00:12:12,929 --> 00:12:15,079
but they're, yeah, you just got to
think about it a little bit more.
256
00:12:15,704 --> 00:12:16,064
Leo Dion (host): right?
257
00:12:16,104 --> 00:12:16,544
Right.
258
00:12:16,694 --> 00:12:21,894
So one of the other things you
ran into with testing was the
259
00:12:21,894 --> 00:12:23,354
problem with persistence, right?
260
00:12:23,684 --> 00:12:28,224
Especially UI testing where you're
like running, like A series of
261
00:12:28,224 --> 00:12:31,494
tests and something does set
some value, then you run the test
262
00:12:31,494 --> 00:12:32,874
again, but that value had been set.
263
00:12:32,874 --> 00:12:34,904
So now you messed stuff up.
264
00:12:35,304 --> 00:12:40,694
Do you in those cases, I mean, for
me, what I typically do is my UI test
265
00:12:40,714 --> 00:12:44,684
just ends up resetting it every time
it runs, maybe as part of setup or
266
00:12:44,684 --> 00:12:46,094
maybe as part of the test itself.
267
00:12:46,344 --> 00:12:49,384
What do you see as a solution
in that, in those cases?
268
00:12:49,849 --> 00:12:51,389
Brandon Williams (guest):
Yeah, that's, the UI test is
269
00:12:51,389 --> 00:12:54,589
particularly tricky because it
runs in a fully separate process.
270
00:12:54,589 --> 00:12:59,919
So even from the XE test file,
you get no way to do stuff.
271
00:12:59,919 --> 00:13:01,269
You can't clear out.
272
00:13:01,634 --> 00:13:03,004
It's user defaults or
anything like that.
273
00:13:03,074 --> 00:13:05,844
Whatever it does with it, you
know, it happens in a process.
274
00:13:05,844 --> 00:13:10,004
That means you get to add the cleanup
code to your actual application project.
275
00:13:10,004 --> 00:13:12,644
And the way you communicate
between the two is to set like a,
276
00:13:12,984 --> 00:13:15,434
I think an environment variable
or something like that to kind of
277
00:13:15,474 --> 00:13:19,684
communicate to your process that,
all right, I'm running in a UI test.
278
00:13:19,724 --> 00:13:23,064
And then you would set up your
dependencies to use like a fake
279
00:13:23,074 --> 00:13:26,094
file system, something that doesn't
write to the desk, but instead
280
00:13:26,104 --> 00:13:27,744
has a little dictionaries mapping.
281
00:13:28,069 --> 00:13:32,389
URLs to data blobs and then and
the application was like, Hey,
282
00:13:32,389 --> 00:13:33,889
load me some data from this URL.
283
00:13:33,889 --> 00:13:35,579
It'll just give you this data blob.
284
00:13:35,579 --> 00:13:37,689
It won't even touch the
file system or anything.
285
00:13:37,999 --> 00:13:40,099
And so that's the way
you typically do it.
286
00:13:40,544 --> 00:13:42,964
Leo Dion (host): I was going to ask,
going back to the talk about protocols
287
00:13:42,964 --> 00:13:44,644
and you're mentioning file system.
288
00:13:44,704 --> 00:13:49,039
Do you end up having a protocol for
pretty much everything that needs to be?
289
00:13:49,479 --> 00:13:51,379
Like mocked essentially.
290
00:13:51,379 --> 00:13:54,739
So Oh, you are, you never use
URL session, use the protocol
291
00:13:54,789 --> 00:13:57,639
and the protocols implementation
might have URL session.
292
00:13:57,639 --> 00:13:58,479
Is that how you do it?
293
00:13:58,984 --> 00:14:00,574
Brandon Williams (guest): Yeah,
essentially you need an interface in
294
00:14:00,574 --> 00:14:01,794
front of each of your dependencies.
295
00:14:01,804 --> 00:14:04,554
So one, whether it's struct or
protocol, but yeah, interface in
296
00:14:04,554 --> 00:14:08,144
front of your API client, interface in
front of your file system, interface
297
00:14:08,144 --> 00:14:13,724
in front of user defaults database,
core location, all those things.
298
00:14:14,089 --> 00:14:16,919
Leo Dion (host): Do you were you
ever an Objective-C developer?
299
00:14:17,144 --> 00:14:17,464
Brandon Williams (guest): Oh yeah.
300
00:14:17,809 --> 00:14:19,979
Leo Dion (host): Do you miss
swizzling and just being
301
00:14:19,979 --> 00:14:21,819
able to change the classes?
302
00:14:22,089 --> 00:14:26,739
I don't, I'm not that kind of developer
but I can, I see a lot of
older, like
303
00:14:26,739 --> 00:14:30,039
Objective-C folks who are just like,
man, I hate how like everything is.
304
00:14:30,459 --> 00:14:34,149
Strong typed and so and that's
like I okay now I see a little bit
305
00:14:34,149 --> 00:14:35,669
of the benefit with Objective-C,
306
00:14:36,059 --> 00:14:37,729
Brandon Williams (guest): Yeah, I
don't really miss it just because
307
00:14:37,729 --> 00:14:40,939
I also remember the terrible
things that when it works great.
308
00:14:40,939 --> 00:14:44,809
But like it injects so much uncertainty
into the rest of your application.
309
00:14:44,809 --> 00:14:46,459
That's really hard to feel comfortable.
310
00:14:46,689 --> 00:14:48,299
And I think other people.
311
00:14:48,659 --> 00:14:50,339
Maybe people are just better
at Objective-C than me.
312
00:14:50,359 --> 00:14:53,809
They just had a higher threshold
for understanding that complex
313
00:14:53,809 --> 00:14:56,289
system all in their head at once,
and I just, I struggled with it.
314
00:14:56,429 --> 00:14:56,649
Leo Dion (host): Yeah.
315
00:14:56,649 --> 00:14:56,849
Yeah.
316
00:14:56,849 --> 00:14:57,199
Yeah.
317
00:14:57,459 --> 00:15:00,319
Brandon Williams (guest): but I think
a lot of this pain around writing these
318
00:15:00,319 --> 00:15:04,159
dependencies, these little interfaces,
a lot of that pain could probably
319
00:15:04,159 --> 00:15:05,769
be mitigated with macros and stuff
320
00:15:05,879 --> 00:15:07,279
Leo Dion (host): Oh Yeah, right.
321
00:15:07,359 --> 00:15:08,469
I figured you're gonna say that.
322
00:15:08,714 --> 00:15:10,614
Brandon Williams (guest): yeah,
so I think we're at least swift as
323
00:15:10,694 --> 00:15:13,584
getting to the point where you will
be able to keep the strong types,
324
00:15:13,584 --> 00:15:16,734
but you'll also have the tools
necessary to put the interfaces in
325
00:15:16,734 --> 00:15:18,104
front of them in a lightweight way.
326
00:15:18,489 --> 00:15:18,779
Leo Dion (host): Yeah.
327
00:15:18,859 --> 00:15:21,629
Yeah Mac I was gonna say macros
is pretty much where that head
328
00:15:21,709 --> 00:15:26,029
that tells you where it's going
was there anything specific you
329
00:15:26,029 --> 00:15:29,819
wanted to mention on testing or
protocols or mocking before I keep?
330
00:15:30,094 --> 00:15:31,424
Keep going further.
331
00:15:31,804 --> 00:15:32,314
Brandon Williams (guest):
yeah all right.
332
00:15:32,314 --> 00:15:38,164
I think one thing I'd like to mention
and is that testing, I just don't think
333
00:15:38,164 --> 00:15:39,964
it's super popular in the iOS community.
334
00:15:39,964 --> 00:15:43,654
I think, if you, I also did a lot
of Ruby back in the day and that
335
00:15:43,654 --> 00:15:47,635
testing and that community is
gigantic and JavaScript's got it.
336
00:15:48,305 --> 00:15:50,735
So and I just I think it's
a little bit unfortunate.
337
00:15:50,985 --> 00:15:54,795
I would kind of encourage people
to just dig in a little bit deep
338
00:15:54,795 --> 00:15:56,765
to see what testing really means.
339
00:15:56,815 --> 00:16:00,565
And this idea of being able to run
your feature in this altered like
340
00:16:00,595 --> 00:16:02,815
execution context is extremely powerful.
341
00:16:02,825 --> 00:16:05,305
All the more you're able to do that.
342
00:16:05,375 --> 00:16:10,935
All it means is your feature is Super
isolatable, super decoupled and can
343
00:16:10,935 --> 00:16:13,605
just be understood all on its own.
344
00:16:13,605 --> 00:16:14,715
And that is incredibly powerful.
345
00:16:14,845 --> 00:16:18,205
And you can only write unit tests
if your feature satisfies that.
346
00:16:18,555 --> 00:16:21,845
And so regardless, I know it's a
lot of people have got like really
347
00:16:21,885 --> 00:16:24,635
hot takes and unpopular opinions on
all these things about testing, I
348
00:16:24,635 --> 00:16:27,895
just, I feel like hopefully just look
through all that fog and kind of.
349
00:16:28,080 --> 00:16:30,240
See what testing can do, because
I think it's incredibly important.
350
00:16:30,340 --> 00:16:32,380
And once you're convinced of that,
I think, yeah, the dependency
351
00:16:32,380 --> 00:16:33,910
stuff is falls out naturally.
352
00:16:33,920 --> 00:16:35,640
You got to do the
dependency controlling.
353
00:16:36,225 --> 00:16:36,445
Leo Dion (host): Yeah.
354
00:16:36,445 --> 00:16:37,365
I agree a hundred percent.
355
00:16:37,415 --> 00:16:40,145
I feel like once you start doing
testing, it's then it's Oh, okay.
356
00:16:40,155 --> 00:16:42,655
Now modularization
makes a lot more sense.
357
00:16:42,925 --> 00:16:47,425
Why do you think, like, why do you think
the community is so testing averse?
358
00:16:47,425 --> 00:16:50,855
Do you think that's a Apple's
fault or tooling fault?
359
00:16:50,895 --> 00:16:55,895
Or is it like, I don't know what
Android is like, but I can imagine it
360
00:16:55,895 --> 00:16:58,205
might be similar with Android as well.
361
00:16:58,215 --> 00:16:58,685
Like just.
362
00:16:58,710 --> 00:17:02,480
Brandon Williams (guest): Java's got
a big testing ethos and history too.
363
00:17:02,480 --> 00:17:04,330
So they do quite a bit of testing also.
364
00:17:04,590 --> 00:17:08,330
I really can't give like a universal
answer why I think it is by some
365
00:17:08,330 --> 00:17:09,660
things that just come to mind are like.
366
00:17:10,410 --> 00:17:12,850
Basically, none of Apple's
sample code has tests.
367
00:17:12,860 --> 00:17:13,990
It's, none of it.
368
00:17:14,220 --> 00:17:18,420
It doesn't matter if they're Fruta, Food
Truck, Scrumding, or all those things.
369
00:17:18,430 --> 00:17:19,220
None of them have tests.
370
00:17:19,810 --> 00:17:22,690
Now, I know Apple does do
testing internally, and I
371
00:17:22,690 --> 00:17:24,480
know it varies team by team.
372
00:17:24,480 --> 00:17:26,950
I know some teams take
it extremely
seriously.
373
00:17:27,250 --> 00:17:30,860
But the sample code, I think Apple's
approach with sample code is they
374
00:17:30,860 --> 00:17:35,635
like to build Fun applications in
the absolute simplest way possible so
375
00:17:35,635 --> 00:17:40,065
that anyone can kind of just roll in
and start messing with things that I
376
00:17:40,075 --> 00:17:41,415
think that's their goal with it because
377
00:17:41,440 --> 00:17:41,670
Leo Dion (host): Yeah.
378
00:17:41,670 --> 00:17:41,840
Yeah.
379
00:17:41,840 --> 00:17:42,150
Yeah.
380
00:17:42,175 --> 00:17:44,335
Brandon Williams (guest): They're
making sample code for millions of
381
00:17:44,345 --> 00:17:49,245
people, but that doesn't necessarily
mean you would go and build your
382
00:17:49,245 --> 00:17:52,925
next company, the infrastructure,
you'd build it in exactly the same
383
00:17:52,925 --> 00:17:54,205
way that Apple does their code.
384
00:17:54,205 --> 00:17:55,545
You know, it's a learning tool.
385
00:17:56,070 --> 00:17:56,190
Leo Dion (host): Yeah.
386
00:17:56,600 --> 00:18:00,240
It's a learning tool and it's also
showing off of this particular API
387
00:18:00,710 --> 00:18:04,250
and to, to them, I'm not agreeing
with them, but to them it's oh unit
388
00:18:04,250 --> 00:18:07,680
tests would just distract away from
the fact that we want to show off.
389
00:18:09,045 --> 00:18:09,355
Brandon Williams (guest): Yeah.
390
00:18:09,385 --> 00:18:11,765
And I think it's, I think it's
under, I think it's reasonable.
391
00:18:11,885 --> 00:18:14,955
I, you know, I certainly wouldn't
agree that, you know, people should be
392
00:18:14,955 --> 00:18:18,225
building their applications in the exact
way that the Fruita truck was built,
393
00:18:18,235 --> 00:18:21,755
but I absolutely understand why they
wouldn't add tests and stuff like that.
394
00:18:21,755 --> 00:18:25,445
They really just want to show here are
all of our fancy new APIs this year.
395
00:18:25,715 --> 00:18:26,665
Here's how to use them.
396
00:18:26,995 --> 00:18:28,755
But yeah, I just don't
think we can look at.
397
00:18:29,105 --> 00:18:32,335
Apple is being like kind of the
pinnacle, their sample goes the pinnacle
398
00:18:32,335 --> 00:18:33,735
of how you should build these things.
399
00:18:34,340 --> 00:18:36,890
Leo Dion (host): So you mentioned
I wouldn't want to build a
400
00:18:36,890 --> 00:18:38,690
whole company app around Fruita.
401
00:18:39,030 --> 00:18:42,100
And that kind of brings us to like
scaling and speed because in the
402
00:18:42,100 --> 00:18:46,580
real world we all work in teams
and have to deal with other people.
403
00:18:46,610 --> 00:18:51,940
And we have to deal with speed issues
with, as far as like you said, if you
404
00:18:51,940 --> 00:18:55,700
don't do this, you have to run this
crap in the simulator every single
405
00:18:55,700 --> 00:18:58,550
time, or you can't even run it in the
simulator, you have to run it on a
406
00:18:58,550 --> 00:19:01,140
device, and that just slows things down.
407
00:19:01,260 --> 00:19:04,490
Yeah, you want to kind of expand
on that, I guess, and why those
408
00:19:04,490 --> 00:19:05,730
are big issues with scaling.
409
00:19:06,160 --> 00:19:10,360
Brandon Williams (guest): Yeah, I think
what, just like with modularization can
410
00:19:10,360 --> 00:19:14,690
help kind of paralyze build times and
speed up compiled times, dependencies
411
00:19:14,710 --> 00:19:19,010
can improve developer experience and
iterative cycle on things because
412
00:19:19,010 --> 00:19:21,180
there are a lot of APIs out there
that we already talked about, yeah,
413
00:19:21,180 --> 00:19:23,940
that don't work in previews, but then
there's a lot of APIs out there that
414
00:19:23,940 --> 00:19:25,260
don't even work in the simulator.
415
00:19:25,470 --> 00:19:26,690
If you're making something that
416
00:19:26,760 --> 00:19:27,460
Leo Dion (host): Core Motion.
417
00:19:27,880 --> 00:19:28,890
Brandon Williams (guest): yeah,
core motion, if you're using
418
00:19:28,890 --> 00:19:29,690
something that uses the gyroscope.
419
00:19:29,985 --> 00:19:32,135
That doesn't work in
the simulator at all.
420
00:19:32,345 --> 00:19:34,165
And so you actually have
to run on the device.
421
00:19:34,165 --> 00:19:35,985
Now you may be thinking of
course I have to run the device.
422
00:19:36,005 --> 00:19:36,675
It's a gyroscope.
423
00:19:36,735 --> 00:19:40,265
I want to be able to move my phone
around but that's not all testing you do
424
00:19:40,265 --> 00:19:42,335
sometimes what you want to do is just.
425
00:19:42,765 --> 00:19:46,325
A simulate that the device is being
thrown around all over the place, and
426
00:19:46,325 --> 00:19:49,065
maybe you've got a little graph that's
showing something, like you don't have
427
00:19:49,065 --> 00:19:52,595
to take your device and do this, instead
you could provide a dependency where
428
00:19:52,595 --> 00:19:56,055
Core Motion is pretending like it's
doing that, you can have the little
429
00:19:56,055 --> 00:20:00,055
gyroscope meters going crazy all over
the place, and you know, that would
430
00:20:00,305 --> 00:20:03,415
massively speed up your developer,
the development cycle, you could even
431
00:20:03,415 --> 00:20:06,195
run that in a preview, you wouldn't
even have to run it in a simulator.
432
00:20:06,570 --> 00:20:10,370
And these kinds of benefits just
really start to compound and explode.
433
00:20:10,380 --> 00:20:15,310
There, there is so much that we
do as developers that is just kind
434
00:20:15,310 --> 00:20:20,320
of working around the quirks of
our code base that we've learned.
435
00:20:20,350 --> 00:20:21,590
We've just learned to do it.
436
00:20:21,600 --> 00:20:26,910
It's just, we've been in the mud for
so long that we know that we don't
437
00:20:26,910 --> 00:20:29,870
want to ever clean this project
because it takes so long to rebuild.
438
00:20:30,030 --> 00:20:33,140
We know that we can't ever run this
project, this feature in isolation.
439
00:20:33,140 --> 00:20:34,600
So I have my little flow of.
440
00:20:34,985 --> 00:20:37,225
Open up the simulator and I tap
tap and I get to the feature
441
00:20:37,225 --> 00:20:38,495
and I can finally test it.
442
00:20:38,815 --> 00:20:42,845
All that stuff starts to kind of peel
away when you can just control your
443
00:20:42,845 --> 00:20:46,765
dependencies and allow yourself to start
up your app in the exact state you want.
444
00:20:46,775 --> 00:20:51,085
You don't have to be susceptible
to all of that dependency
445
00:20:51,125 --> 00:20:52,015
corrupt and everything.
446
00:20:52,025 --> 00:20:53,575
You should control all that.
447
00:20:53,970 --> 00:20:54,310
Leo Dion (host): Yeah.
448
00:20:54,650 --> 00:20:56,720
Yeah, I'm sorry.
449
00:20:56,750 --> 00:21:00,500
I was like thinking about Apple
trying to unit test their like crash
450
00:21:00,500 --> 00:21:02,700
detection and how they possibly do that.
451
00:21:02,710 --> 00:21:05,720
Do they like throw the phone
against the wall or what do they do?
452
00:21:05,730 --> 00:21:08,130
Because, yeah, I would hope
that they have some mocking
453
00:21:08,130 --> 00:21:09,590
system for something like that.
454
00:21:09,930 --> 00:21:13,000
Because, yeah, like you said, there's
all these little quirks that you run
455
00:21:13,000 --> 00:21:17,630
into where it's you need the flexibility
of putting something in to replace it.
456
00:21:18,110 --> 00:21:19,950
Brandon Williams (guest): That brings
up, you bring up an interesting point
457
00:21:19,950 --> 00:21:22,900
also is that there's also a bit of
a spectrum with this testing, too,
458
00:21:23,040 --> 00:21:26,380
because you've got the unit tests
at one end where you mock things
459
00:21:26,380 --> 00:21:29,790
because you just want to say, I
assume the outside world is doing
460
00:21:29,790 --> 00:21:33,290
what I expect, but I want, I just want
to test my little nugget of logic.
461
00:21:33,550 --> 00:21:36,180
And then at the other end, you've got
integration testing where you start
462
00:21:36,180 --> 00:21:37,980
to pull in more of the outside world.
463
00:21:38,230 --> 00:21:39,250
And that's extremely important.
464
00:21:39,250 --> 00:21:42,090
It's, I'm not saying that one side
is better than the other there.
465
00:21:42,345 --> 00:21:46,045
You absolutely should be testing along
multiple points of this spectrum.
466
00:21:46,235 --> 00:21:49,695
And like this crash testing they, I
assume they probably do actually have
467
00:21:49,695 --> 00:21:52,945
some little laboratory setup, where
they literally throw phones around.
468
00:21:53,135 --> 00:21:56,085
And that's great, because, you
know, they wanna know, like,
469
00:21:56,095 --> 00:21:58,625
when, at the end of the day,
this thing is working that way.
470
00:21:58,830 --> 00:22:01,630
But then that other thing they
want to test is just that an
471
00:22:01,640 --> 00:22:03,940
alert pops up with this messaging.
472
00:22:03,980 --> 00:22:05,460
I don't think you need to
throw the phone across the
473
00:22:05,460 --> 00:22:06,950
room just to test an alert.
474
00:22:07,150 --> 00:22:07,430
Leo Dion (host): right.
475
00:22:07,550 --> 00:22:09,300
Brandon Williams (guest): would
instead, you would just, you
476
00:22:09,300 --> 00:22:12,450
know, make it fake like it did a
crash and then you see the alert.
477
00:22:12,460 --> 00:22:14,870
So there's like a spectrum
there and you got to test at
478
00:22:14,890 --> 00:22:16,320
every level of the spectrum.
479
00:22:17,070 --> 00:22:18,740
Leo Dion (host): Do you think
one side of the spectrum is
480
00:22:18,740 --> 00:22:19,890
more important than the other?
481
00:22:20,470 --> 00:22:21,390
Brandon Williams (guest): I do not.
482
00:22:21,730 --> 00:22:22,090
Leo Dion (host): Okay.
483
00:22:22,110 --> 00:22:25,750
Brandon Williams (guest): I think
you really need a full around overall
484
00:22:25,810 --> 00:22:27,660
you know, testing on all sides of it.
485
00:22:27,860 --> 00:22:28,500
You really do.
486
00:22:29,500 --> 00:22:30,900
Leo Dion (host): What was I gonna ask?
487
00:22:31,315 --> 00:22:33,235
Brandon Williams (guest): I will
say that certainly the integration
488
00:22:33,235 --> 00:22:35,175
side is the hardest side to test.
489
00:22:35,175 --> 00:22:38,165
And so typically you've got fewer
tests over there because then you
490
00:22:38,165 --> 00:22:40,225
can't really make absolute assertions.
491
00:22:40,225 --> 00:22:43,115
You can't say, oh, I made this network
request and I got this exact thing.
492
00:22:43,115 --> 00:22:47,075
Instead, you can just say, oh, I made
this network request, it fed into my
493
00:22:47,085 --> 00:22:51,885
system and, you know, I can assert
that at least something happened,
494
00:22:51,885 --> 00:22:54,385
but I can't assert that exactly what
happened because you can't predict it.
495
00:22:54,385 --> 00:22:54,515
But.
496
00:22:54,915 --> 00:22:58,515
Yeah, integration testing is
far harder than unit testing.
497
00:23:00,025 --> 00:23:03,345
Leo Dion (host): I think now we can
jump into the muck that is how do
498
00:23:03,345 --> 00:23:05,285
we deal with all these dependencies?
499
00:23:05,775 --> 00:23:11,635
So the way I watch your try swift talk
or new york swift talk, excuse me and
500
00:23:11,695 --> 00:23:12,045
Brandon Williams (guest): right?
501
00:23:12,375 --> 00:23:14,065
Leo Dion (host): No,
you're It was your talk.
502
00:23:14,075 --> 00:23:14,465
Yeah.
503
00:23:14,865 --> 00:23:15,555
In New York.
504
00:23:15,825 --> 00:23:17,205
Brandon Williams (guest):
the one from in April
505
00:23:17,255 --> 00:23:17,395
Leo Dion (host): Yeah.
506
00:23:17,645 --> 00:23:17,965
Sorry.
507
00:23:18,385 --> 00:23:22,815
So I watched that and I was like
my solution is supply default
508
00:23:23,245 --> 00:23:25,915
implementations that are the real thing.
509
00:23:25,935 --> 00:23:31,395
And then in your previews and in your
tests, you're just customize them.
510
00:23:31,395 --> 00:23:31,635
Right.
511
00:23:32,045 --> 00:23:32,875
That's the way I do it.
512
00:23:33,135 --> 00:23:34,245
But you don't like that.
513
00:23:34,415 --> 00:23:35,095
And I liked it.
514
00:23:35,125 --> 00:23:38,135
You had a really good quote that
I say defaults are ergonomic,
515
00:23:38,135 --> 00:23:41,035
but not safe and requirements
are safe, but not ergonomic.
516
00:23:41,085 --> 00:23:42,565
Do you want to explain that?
517
00:23:42,825 --> 00:23:43,445
I guess.
518
00:23:43,600 --> 00:23:43,840
Brandon Williams (guest): Yeah.
519
00:23:44,010 --> 00:23:48,380
So they so yeah, the easiest way to
provide dependencies to your various
520
00:23:48,380 --> 00:23:52,590
features is you have an initial you
hold the dependency as a property and
521
00:23:52,630 --> 00:23:57,270
you know, whatever your thing is a view
controller or observable object and
522
00:23:57,270 --> 00:24:01,930
you provide an initializer that has
a default, which is the live thing.
523
00:24:01,930 --> 00:24:02,710
So the thing that.
524
00:24:03,065 --> 00:24:06,495
makes network request or the thing
that actually accesses core location.
525
00:24:06,495 --> 00:24:09,195
And that way, if you construct
that feature and don't provide
526
00:24:09,195 --> 00:24:13,425
anything, it gets the live dependency
and it all seems really good.
527
00:24:13,585 --> 00:24:16,795
And then over in previews, you
get the opportunity to then.
528
00:24:17,165 --> 00:24:19,525
provide one of those mock things.
529
00:24:19,805 --> 00:24:20,075
All right.
530
00:24:20,085 --> 00:24:24,095
So that can be a really good
way to get your feet wet and
531
00:24:24,095 --> 00:24:25,415
start getting things going.
532
00:24:25,645 --> 00:24:29,705
And it's very ergonomic because it means
you could have some deep leaf feature.
533
00:24:29,705 --> 00:24:32,325
You could be drilled down
multiple levels into your
534
00:24:32,325 --> 00:24:35,055
application and you could be
like, Oh wait, this feature now.
535
00:24:35,945 --> 00:24:36,985
A network client.
536
00:24:36,995 --> 00:24:39,015
So I'm just going to provide
it, provide that default.
537
00:24:39,075 --> 00:24:40,115
Everything compiles.
538
00:24:40,135 --> 00:24:40,775
It's all good.
539
00:24:40,785 --> 00:24:41,655
So that's super ergonomic.
540
00:24:41,705 --> 00:24:44,575
You get to add dependencies
with no trouble whatsoever.
541
00:24:44,805 --> 00:24:49,645
However I call that not being safe
because what it means is say some
542
00:24:49,685 --> 00:24:53,145
other feature up the hierarchy
also wanted a network client.
543
00:24:53,445 --> 00:24:53,845
All right.
544
00:24:53,935 --> 00:24:58,145
If it doesn't pass its network
client down to every feature
545
00:24:58,165 --> 00:24:59,755
along the way
so that leaf.
546
00:25:00,755 --> 00:25:03,625
And then you run into the situation
where you could be running a
547
00:25:03,635 --> 00:25:05,315
preview of that parent feature.
548
00:25:05,525 --> 00:25:09,015
The parent feature is using the
mock network client, but that leaf
549
00:25:09,025 --> 00:25:10,535
feature is using the live one.
550
00:25:10,785 --> 00:25:14,085
Because no one passed it all the
way down to the leaf feature.
551
00:25:14,535 --> 00:25:16,295
And so that's why it's unsafe.
552
00:25:16,295 --> 00:25:20,565
That you will accidentally use live
dependencies when you don't expect it.
553
00:25:20,575 --> 00:25:24,375
Unless you're strict with yourself
to pass them explicitly along.
554
00:25:25,115 --> 00:25:26,565
Leo Dion (host): That's what I
mean, that's kind of what I do.
555
00:25:26,565 --> 00:25:27,965
And I would just pass them along.
556
00:25:28,335 --> 00:25:32,085
I would still supply the default, but
I would pass it along, but I understand
557
00:25:32,085 --> 00:25:33,415
where you're coming from completely.
558
00:25:34,045 --> 00:25:36,165
Brandon Williams (guest): Gives
the ergonomics, but it takes away
559
00:25:36,165 --> 00:25:39,555
the safety because then it's on
you to remember to pass along
560
00:25:39,555 --> 00:25:40,955
because the compiler can't help you.
561
00:25:41,085 --> 00:25:43,675
If you don't pass it, it's you
got a default, no big deal.
562
00:25:43,875 --> 00:25:45,994
So that's where the safety bar comes in.
563
00:25:46,264 --> 00:25:47,714
Leo Dion (host): Macro save us, please.
564
00:25:48,284 --> 00:25:48,694
Yeah.
565
00:25:48,724 --> 00:25:51,484
I mean, essentially what you
get I like that solution.
566
00:25:51,534 --> 00:25:52,314
And part of that.
567
00:25:53,454 --> 00:25:56,634
I don't want to have to add another
dependency, which is kind of what
568
00:25:56,634 --> 00:26:01,464
you get at is having to add some
sort of dependency injection library.
569
00:26:01,724 --> 00:26:05,794
And I'm actually in my previous
life we used when I was a.
570
00:26:05,994 --> 00:26:09,624
net developer C sharp, we did
we used what was it was Castle
571
00:26:09,624 --> 00:26:13,484
Windsor, I believe was the
dependency injection tool.
572
00:26:13,484 --> 00:26:14,694
And I thought it was awesome.
573
00:26:14,704 --> 00:26:16,734
Like it was amazing how it worked.
574
00:26:16,744 --> 00:26:18,084
And I wish.
575
00:26:19,084 --> 00:26:23,854
And I think maybe macros actually
might help with this as far as
576
00:26:23,854 --> 00:26:27,504
dependency injection is concerned,
but basically there's a plethora of
577
00:26:27,504 --> 00:26:31,694
library and of course you at point
three, you have one as well that
578
00:26:31,694 --> 00:26:33,524
kind of try to solve this problem.
579
00:26:33,524 --> 00:26:36,824
I don't, I know what dependency
injection is, but I'll let you go ahead
580
00:26:36,824 --> 00:26:39,864
and explain that and then what these
tools actually do and how they're.
581
00:26:40,084 --> 00:26:45,114
that kind of fit the role that
you think is better than the the
582
00:26:45,114 --> 00:26:46,484
way we suggested with defaults.
583
00:26:46,979 --> 00:26:47,229
Brandon Williams (guest): Sure.
584
00:26:47,229 --> 00:26:47,609
Yeah.
585
00:26:47,609 --> 00:26:47,809
All right.
586
00:26:47,819 --> 00:26:51,889
So if you go down the route of finally
controlling your dependencies, and you
587
00:26:51,889 --> 00:26:56,589
provide initializers to pass them in
explicitly, and you find that to be non
588
00:26:56,589 --> 00:27:00,289
ergonomic, so then you throw in some
defaults, and then you find that to
589
00:27:00,299 --> 00:27:06,619
be not safe, The only point of adding
a library to this entire system is to
590
00:27:06,889 --> 00:27:11,599
find a balance between something that is
pretty ergonomic and also pretty safe.
591
00:27:11,809 --> 00:27:16,169
You'll never have the fullness of
ergonomics and safety at the same time.
592
00:27:16,169 --> 00:27:16,329
There
593
00:27:16,394 --> 00:27:17,224
Leo Dion (host): It's a compromise.
594
00:27:17,504 --> 00:27:20,224
Brandon Williams (guest): Yeah
but initializers that don't
595
00:27:20,224 --> 00:27:23,664
have defaults are extremely
safe, not ergonomic at all.
596
00:27:23,834 --> 00:27:28,294
And then initializers with defaults are
extremely ergonomic, not safe at all.
597
00:27:28,294 --> 00:27:30,514
So you're trying to find
somewhere in between those two.
598
00:27:30,864 --> 00:27:34,494
And that's the only purpose of a
dependency injection framework is
599
00:27:34,684 --> 00:27:39,164
allow you to provide The network client
and the core location client to the
600
00:27:39,164 --> 00:27:43,044
feature that wants it in a way that's
slightly ergonomic and slightly safe.
601
00:27:43,244 --> 00:27:47,884
And where you draw the line
there is like up to the library.
602
00:27:48,074 --> 00:27:49,464
And so we've got our own library.
603
00:27:49,464 --> 00:27:52,824
There's probably a dozen or more
other libraries in the Iowa community.
604
00:27:53,154 --> 00:27:57,434
And we, yeah, we try to strike our
balance between those two things.
605
00:27:58,204 --> 00:28:02,554
Leo Dion (host): The idea being is
you can say you know, use this type
606
00:28:02,614 --> 00:28:06,674
and then you tell the dependency
injection, use this type essentially.
607
00:28:06,704 --> 00:28:11,104
And then basically a singleton, you
kind of resolve it and then it gives
608
00:28:11,104 --> 00:28:12,744
you the type that you had already set.
609
00:28:13,224 --> 00:28:14,184
Is that right?
610
00:28:14,344 --> 00:28:16,014
Brandon Williams (guest): Yeah,
essentially you'll have some kind
611
00:28:16,014 --> 00:28:19,804
of way of annotating in your feature
like a view controller observable
612
00:28:19,834 --> 00:28:24,464
object saying this object wants
a dependency of this type and it
613
00:28:24,464
--> 00:28:28,614
will be the job of the dependency
injection library to figure out where
614
00:28:28,624 --> 00:28:29,384
does it get that thing concurrency.
615
00:28:30,384 --> 00:28:32,834
Pretty much the only way to do this
would have been you do have this
616
00:28:32,854 --> 00:28:37,844
global Singleton of dependencies and
you get to pick from it and provide
617
00:28:37,844 --> 00:28:42,029
it to to features, but then there
would be additional Functionality.
618
00:28:42,029 --> 00:28:46,129
Maybe you can scope that global
singleton to something smaller so that
619
00:28:46,139 --> 00:28:49,219
this set of features gets a little
bit slightly different dependencies.
620
00:28:49,229 --> 00:28:51,549
There's there's other things you
can do and there's something called
621
00:28:51,549 --> 00:28:55,539
containers and stuff like that you
can really dive into if you want.
622
00:28:55,839 --> 00:28:59,689
But post Swift Concurrency, there's
now something called Task Locals.
623
00:28:59,729 --> 00:29:03,019
And Task Locals allow you to
have something that looks...
624
00:29:03,454 --> 00:29:05,604
global, but it's actually quite safe.
625
00:29:05,614 --> 00:29:09,824
It can be thread safe or it is
thread safe and it plays nicely
626
00:29:09,824 --> 00:29:11,174
with structured concurrency.
627
00:29:11,374 --> 00:29:15,334
And so that's the tool we use
to build our dependency library.
628
00:29:15,344 --> 00:29:18,494
All of dependencies are
basically held in a task local.
629
00:29:18,544 --> 00:29:22,444
Leo Dion (host): I mean to me like the
drawback with that is, For one thing,
630
00:29:22,454 --> 00:29:24,904
do you ever see Apple coming in or?
631
00:29:25,194 --> 00:29:27,674
I'm just saying here's a
dependency injection way to do
632
00:29:27,724 --> 00:29:29,434
things using macros or whatever.
633
00:29:29,704 --> 00:29:31,014
Do you think that could ever happen?
634
00:29:31,024 --> 00:29:33,614
Or do you think that we're pretty
much going to have to bring in
635
00:29:33,614 --> 00:29:35,124
third party libraries to do this?
636
00:29:35,674 --> 00:29:37,454
Brandon Williams (guest): I think
it could theoretically happen.
637
00:29:37,504 --> 00:29:42,614
It would be surprising only for
the fact that Apple has never once
638
00:29:42,614 --> 00:29:47,604
shown any interest whatsoever in The
idea of controlling dependencies.
639
00:29:47,624 --> 00:29:51,164
They do not even build APIs that are.
640
00:29:51,754 --> 00:29:52,754
control friendly.
641
00:29:52,754 --> 00:29:55,164
Like, all right, for example, the
standard library has some, like,
642
00:29:55,164 --> 00:29:58,054
all right so when Swift concurrency
first came out, we had task.
643
00:29:58,264 --> 00:30:01,984
sleep, and that was a way to
sleep an async context for some
644
00:30:01,984 --> 00:30:05,034
amount of time, but that is a
completely uncontrolled dependency.
645
00:30:05,034 --> 00:30:07,834
If you sprinkle that into your
code and then try to test that
646
00:30:07,834 --> 00:30:10,979
code, Your test will just literally
have to wait for time to pass.
647
00:30:10,989 --> 00:30:14,379
So if you needed to wait 10 seconds
before something happened in your
648
00:30:14,379 --> 00:30:17,189
feature, like confetti or something,
you would just, your test would
649
00:30:17,199 --> 00:30:18,509
have to just wait 10 seconds.
650
00:30:18,779 --> 00:30:22,959
So then in the next, like in a update
to Swift concurrency, they released the
651
00:30:22,959 --> 00:30:27,169
clock protocol, which is an abstraction
and interface in front of sleeping.
652
00:30:27,469 --> 00:30:30,229
And then that allows you
to substitute in clocks.
653
00:30:30,379 --> 00:30:33,629
You get to use a continuous
clock when run on a device,
654
00:30:33,629 --> 00:30:36,999
but you could use an immediate
clock or a test clock and test.
655
00:30:37,464 --> 00:30:42,034
So that is one of the only examples
I can think of Apple providing
656
00:30:42,054 --> 00:30:46,364
interfaces that actually make testing
easier, like all their other APIs
657
00:30:46,624 --> 00:30:51,654
core location, core, locate, motion,
context, framework, all of those,
658
00:30:51,664 --> 00:30:54,904
you just get types, you don't get
interfaces in front of those types.
659
00:30:55,294 --> 00:30:55,674
Leo Dion (host): Right.
660
00:30:55,744 --> 00:30:56,264
Right.
661
00:30:56,364 --> 00:30:57,704
Brandon Williams (guest):
it would be surprising to me
662
00:30:57,734 --> 00:30:59,664
if Apple came out with some.
663
00:31:00,334 --> 00:31:02,784
You know, wonderful way of
doing dependency management.
664
00:31:02,814 --> 00:31:05,794
Now, however, I'll say SwiftUI is.
665
00:31:06,729 --> 00:31:09,859
From its very foundation,
a gigantic dependency
666
00:31:09,859 --> 00:31:11,159
management system, essentially.
667
00:31:11,159 --> 00:31:13,339
Like environment variables
and environment objects.
668
00:31:13,529 --> 00:31:15,799
That is all about how do you
take something and push it
669
00:31:15,799 --> 00:31:17,169
deep into a view hierarchy.
670
00:31:17,389 --> 00:31:20,909
So we've got the tool at the view
layer but I think that was probably
671
00:31:20,959 --> 00:31:25,489
out of just pure necessity of wanting
the idea of if you set a foreground
672
00:31:25,489 --> 00:31:27,999
color on this view, the fact that
it needs to be able to trickle deep
673
00:31:27,999 --> 00:31:32,549
into the view hierarchy, I think
That, that drove that nec necessity.
674
00:31:32,549 --> 00:31:35,399
It wasn't that they were like,
oh, we've got dependency clients.
675
00:31:35,399 --> 00:31:37,379
We need to control, therefore
we need the environment value.
676
00:31:37,379 --> 00:31:38,514
I don't think that was their line of
677
00:31:38,779 --> 00:31:39,119
Leo Dion (host): Right.
678
00:31:39,159 --> 00:31:39,599
Right.
679
00:31:40,014 --> 00:31:41,974
Brandon Williams (guest): and so
what our dependency library, what we
680
00:31:41,974 --> 00:31:45,304
take inspiration from the environment
values and we try to give a tool
681
00:31:45,304 --> 00:31:48,904
that looks like environment values,
but you can use it in observable
682
00:31:48,904 --> 00:31:50,614
objects and stuff like that.
683
00:31:51,079 --> 00:31:55,519
Leo Dion (host): I was wondering if that
was like a limitation of Objective-C and
684
00:31:55,519 --> 00:31:58,279
they're like, yeah, we're not going to
do because we can do a bunch of other
685
00:31:58,279 --> 00:31:59,699
stuff we had talked about previously.
686
00:32:00,069 --> 00:32:03,929
But then I'm like, yeah, all
these new Swift APIs are all.
687
00:32:05,379 --> 00:32:07,129
said not protocols or interfaces.
688
00:32:07,129 --> 00:32:08,829
They're just types like Swift data.
689
00:32:09,199 --> 00:32:12,489
It's all strongly typed So yeah, okay.
690
00:32:12,509 --> 00:32:12,849
Yeah.
691
00:32:13,259 --> 00:32:13,589
Yeah
692
00:32:14,114 --> 00:32:16,454
Brandon Williams (guest): Yeah I
can definitely buy the argument
693
00:32:16,464 --> 00:32:20,484
that Apple didn't really ever see
a need for dependency management
694
00:32:20,684 --> 00:32:21,694
control and stuff like that.
695
00:32:21,694 --> 00:32:24,664
And Objective-C day, because
everything was so loosey goosey with
696
00:32:24,704 --> 00:32:26,264
message dispatch and stuff like that.
697
00:32:26,484 --> 00:32:30,034
I just, I don't know what
their plan is for swift.
698
00:32:30,034 --> 00:32:33,794
I don't know how people
within, you know, app like the
699
00:32:33,794 --> 00:32:35,304
people building the weather
700
00:32:35,349 --> 00:32:37,619
Leo Dion (host): Have you ever
looked at any of the open source
701
00:32:37,629 --> 00:32:39,059
stuff and seen how they do it?
702
00:32:39,849 --> 00:32:40,359
Like
703
00:32:40,684 --> 00:32:41,504
Brandon Williams (guest):
what open stuff do they
704
00:32:41,779 --> 00:32:46,049
Leo Dion (host): I don't know like
foundation or collections or algorithms
705
00:32:46,234 --> 00:32:48,434
Brandon Williams (guest): those are
like foundational libraries that
706
00:32:48,434 --> 00:32:50,014
don't benefit from this kind of thing.
707
00:32:50,014 --> 00:32:50,184
It
708
00:32:50,259 --> 00:32:50,949
Leo Dion (host): Yeah, right,
709
00:32:51,034 --> 00:32:52,514
Brandon Williams (guest): If they
ever open source the weather app,
710
00:32:52,524 --> 00:32:56,414
I'd be very curious how they deal
with things in the weather app.
711
00:32:56,444 --> 00:32:57,704
You know, something like that.
712
00:32:57,919 --> 00:32:58,589
Leo Dion (host): right, right.
713
00:32:59,269 --> 00:33:03,209
Yeah, I think we
covered most everything.
714
00:33:03,349 --> 00:33:06,179
I do, was there anything
else you want to talk about
715
00:33:06,179 --> 00:33:08,239
before we jump into WW at all?
716
00:33:09,099 --> 00:33:09,269
Brandon Williams (guest): No.
717
00:33:09,269 --> 00:33:10,599
I mean, maybe something
will come up, but
718
00:33:10,794 --> 00:33:10,934
Leo Dion (host): Yeah.
719
00:33:11,099 --> 00:33:11,659
Brandon Williams (guest):
to mind right now.
720
00:33:11,824 --> 00:33:15,964
Leo Dion (host): So I was going
to ask more focused on WWDC
721
00:33:16,004 --> 00:33:20,464
has any of let's start with the
Swift UI and observation stuff.
722
00:33:20,464 --> 00:33:25,044
Has that changed any of your
views as far as how dependencies
723
00:33:25,044 --> 00:33:28,104
should be managed or is it pretty
much, Oh yeah, it's all the same.
724
00:33:28,104 --> 00:33:31,834
Cause there was a lot of stuff, you
know, with like property wrappers
725
00:33:31,964 --> 00:33:33,534
that essentially are kind of like.
726
00:33:33,854 --> 00:33:36,324
Not needed anymore
because of observation.
727
00:33:36,754 --> 00:33:39,604
Has that changed any of your views
on dependency management when
728
00:33:39,604 --> 00:33:40,974
it comes to especially Swift UI?
729
00:33:41,644 --> 00:33:43,574
Brandon Williams (guest): It
has not changed any of the core
730
00:33:43,574 --> 00:33:47,704
views of dependencies, but the
observation tracking stuff does
731
00:33:47,734 --> 00:33:51,994
open up a new possibility, new
powers we could possibly give a
732
00:33:52,004 --> 00:33:55,204
dependency library like our library
or anyone can add to the library.
733
00:33:55,204 --> 00:33:58,294
So one of the things that we do
with our dependency library is that.
734
00:33:58,524 --> 00:34:01,584
If you start using it in your feature
and then you write a unit test for
735
00:34:01,584 --> 00:34:06,204
that feature and you don't override
the dependency in the test, you
736
00:34:06,204 --> 00:34:09,734
get a test failure the moment your
feature even accesses the dependency.
737
00:34:09,784 --> 00:34:12,894
So if you got like a
method that says the.
738
00:34:13,364 --> 00:34:17,204
You know, load data button
tapped and inside there, you
739
00:34:17,204 --> 00:34:18,294
go into your network client.
740
00:34:18,304 --> 00:34:23,104
You're like, oh, load data that
will trigger a test failure because
741
00:34:23,684 --> 00:34:27,444
the opinion of our library is that
if you accidentally use a live
742
00:34:27,444 --> 00:34:30,944
dependency in a test, that is most
likely not the thing you want to do.
743
00:34:31,154 --> 00:34:34,504
And so we complain really loudly
saying you're using a live dependency.
744
00:34:34,504 --> 00:34:35,704
You probably don't mean this.
745
00:34:35,734 --> 00:34:38,774
If you do mean this, you can be
explicitly say, I do mean this, but
746
00:34:38,794 --> 00:34:39,104
Leo Dion (host): Right.
747
00:34:39,144 --> 00:34:39,714
Right.
748
00:34:39,904 --> 00:34:40,184
Brandon Williams (guest): right?
749
00:34:40,214 --> 00:34:43,524
And so then there's so we force you
to override that dependency and we
750
00:34:43,524 --> 00:34:46,524
have a tool that allows you to write
your test where you get to override
751
00:34:46,524 --> 00:34:52,104
the dependency, but there's a flip
side to that where if you then you
752
00:34:52,104 --> 00:34:55,124
construct your model in the test and
you override all its dependencies,
753
00:34:55,134 --> 00:34:59,034
but say you override too many
dependencies, there is the idea
754
00:34:59,034 --> 00:35:00,444
that maybe that should be a failure.
755
00:35:00,534 --> 00:35:02,744
If you override dependency that
wasn't actually used, yeah.
756
00:35:03,619 --> 00:35:05,709
Maybe that should be a failure
because then you get to trim
757
00:35:05,709 --> 00:35:08,639
down the dependencies you
override to the bare minimum.
758
00:35:08,829 --> 00:35:12,139
And that really allows you to prove that
you know how this feature is working.
759
00:35:12,419 --> 00:35:15,869
And that kind of, being able to have
that insight of what features are being,
760
00:35:15,869 --> 00:35:18,659
what dependency endpoints are being
used and which ones are not being used.
761
00:35:18,849 --> 00:35:20,739
I think all the observation
tracking will help with that.
762
00:35:20,739 --> 00:35:24,129
And that's a completely non
SwiftUI application of that tool.
763
00:35:24,359 --> 00:35:27,189
Just the idea of the observation
in general I think will be.
764
00:35:27,529 --> 00:35:30,939
Really, and it's just going to allow us
to build some very interesting tools.
765
00:35:31,239 --> 00:35:34,309
But the idea of controlling
dependencies, observation alone,
766
00:35:34,329 --> 00:35:36,089
doesn't really change that story.
767
00:35:36,399 --> 00:35:37,089
Leo Dion (host): Right, right.
768
00:35:37,449 --> 00:35:39,539
How about as far as like using macros?
769
00:35:40,379 --> 00:35:43,689
Brandon Williams (guest): Macros
just will make, finally, controlling
770
00:35:43,689 --> 00:35:45,079
your dependencies more ergonomic.
771
00:35:45,159 --> 00:35:49,019
It may be using our library more
ergonomic, but, yeah, it doesn't
772
00:35:49,019 --> 00:35:51,159
change the reason to do it or
773
00:35:51,199 --> 00:35:52,129
Leo Dion (host): Right, right.
774
00:35:52,809 --> 00:35:56,559
But now you have syntactic
sugar to spread around to
775
00:35:56,559 --> 00:35:58,099
make it a lot easier to do.
776
00:35:58,499 --> 00:35:58,879
Yeah.
777
00:35:58,934 --> 00:36:01,494
Brandon Williams (guest): The, for
example, like registering a dependency
778
00:36:01,494 --> 00:36:03,814
within the library so that you
can start using in your features.
779
00:36:03,834 --> 00:36:07,524
It is a multi step process, just like
with environment values, you have to
780
00:36:07,524 --> 00:36:09,064
create this like little environment.
781
00:36:09,124 --> 00:36:12,374
For SwiftUI environment values, you
create an environment key, you conform
782
00:36:12,374 --> 00:36:16,144
it to a protocol, you extend environment
values, you add a computed property.
783
00:36:16,339 --> 00:36:17,059
Leo Dion (host): Right, right.
784
00:36:17,184 --> 00:36:19,794
Brandon Williams (guest): all of
that could be macrofied and, you
785
00:36:19,794 --> 00:36:21,914
know, a one stop kind of thing,
786
00:36:22,109 --> 00:36:24,469
Leo Dion (host): Have you jumped
into creating your own macros yet?
787
00:36:24,964 --> 00:36:26,744
Brandon Williams (guest): Yeah, we've
experimented with it quite a bit.
788
00:36:26,794 --> 00:36:30,434
Mostly for our KSPAS library
and composable architecture
789
00:36:30,434 --> 00:36:31,274
and stuff like that.
790
00:36:31,794 --> 00:36:32,054
Yeah.
791
00:36:32,739 --> 00:36:35,179
Leo Dion (host): Pretty easy,
comfortable getting into swim
792
00:36:35,189 --> 00:36:36,859
syntax and stuff, or what?
793
00:36:37,304 --> 00:36:38,524
Brandon Williams (guest):
Swift Syntax is a beast.
794
00:36:38,524 --> 00:36:38,984
It's it's
795
00:36:39,154 --> 00:36:39,754
Leo Dion (host): know it is.
796
00:36:39,774 --> 00:36:40,204
Brandon Williams (guest): yeah.
797
00:36:40,574 --> 00:36:44,094
And you really need autocomplete to
help you out every step of the way.
798
00:36:44,094 --> 00:36:46,444
Cause that is, yeah,
there's so much there.
799
00:36:46,474 --> 00:36:52,539
There's like this AST, Swift Syntax
Explorer website that allows you just to
800
00:36:52,539 --> 00:36:56,879
paste in some Swift code and it prints
out the Swift syntax code alongside it.
801
00:36:56,879 --> 00:36:59,609
So you can kind of just see what every
little thing corresponds to and that
802
00:36:59,634 --> 00:36:59,864
Leo Dion (host): Yeah.
803
00:36:59,864 --> 00:37:00,244
Yeah.
804
00:37:00,689 --> 00:37:01,629
Brandon Williams (guest):
what the heck is going on.
805
00:37:01,629 --> 00:37:03,969
But yeah, it's Swift Syntax is a beast.
806
00:37:04,224 --> 00:37:05,124
Leo Dion (host): I'm glad you said that.
807
00:37:05,144 --> 00:37:05,744
Not chat GPT.
808
00:37:06,124 --> 00:37:06,544
That's good.
809
00:37:06,974 --> 00:37:07,234
Brandon Williams (guest): Yeah.
810
00:37:08,234 --> 00:37:11,934
Leo Dion (host): And then last but not
least with data, where do you see that
811
00:37:11,944 --> 00:37:15,784
fits in as far as dependency management
is concerned and mocking that?
812
00:37:15,984 --> 00:37:18,414
I mean, I guess you've already
had stuff with core data, which
813
00:37:18,434 --> 00:37:20,914
of course is a dependency as well.
814
00:37:20,924 --> 00:37:22,374
That's certainly a wild card.
815
00:37:22,694 --> 00:37:24,974
Is it kind of the same
way with Swift data?
816
00:37:25,684 --> 00:37:26,214
Brandon Williams (guest): So what?
817
00:37:26,224 --> 00:37:27,834
Yeah, it's basically the same story.
818
00:37:27,834 --> 00:37:28,514
I think so.
819
00:37:28,554 --> 00:37:32,464
So it's really just to enter like
a nicer API on top of core data
820
00:37:32,534 --> 00:37:33,614
Leo Dion (host): Oh yeah, exactly.
821
00:37:33,804 --> 00:37:34,044
Yeah.
822
00:37:34,044 --> 00:37:34,224
Yeah.
823
00:37:34,334 --> 00:37:35,674
Brandon Williams (guest): I
think that story is the same.
824
00:37:35,674 --> 00:37:36,274
But what?
825
00:37:36,584 --> 00:37:36,844
Sorry.
826
00:37:36,844 --> 00:37:39,064
So one thing that's interesting
about core data, and I think I
827
00:37:39,074 --> 00:37:41,064
misspoke a little earlier when
I was like, I'm trying to think
828
00:37:41,064 --> 00:37:42,979
of examples where Apple is made.
829
00:37:43,359 --> 00:37:47,319
APIs that are control friendly
or testable friendly core data
830
00:37:47,329 --> 00:37:49,079
actually does have a little
bit of that because it has the
831
00:37:49,089 --> 00:37:50,839
concept of the in memory store.
832
00:37:50,989 --> 00:37:53,869
You know, usually when you're running
in the simulator on device, you're
833
00:37:54,019 --> 00:37:55,719
Leo Dion (host): it writes
it to a SQLite file.
834
00:37:55,749 --> 00:37:56,079
Yeah.
835
00:37:56,569 --> 00:37:57,919
Brandon Williams (guest): and
there is the option where you get
836
00:37:57,919 --> 00:38:00,989
to say, all right I want to load
up my application and I don't want
837
00:38:00,989 --> 00:38:02,069
to use that sequel light file.
838
00:38:02,089 --> 00:38:04,189
I just want to say I want
it all to be in memory.
839
00:38:04,189 --> 00:38:08,659
That way, when the application is
killed, no data was persisted and that
840
00:38:08,659 --> 00:38:10,169
can be incredibly helpful for you.
841
00:38:10,169 --> 00:38:11,849
I test and unit tests
and stuff like that.
842
00:38:11,849 --> 00:38:15,009
So that's a really good tool, but
That's the same story, regardless
843
00:38:15,009 --> 00:38:17,679
of Swift data or core data that's
just kind of been carried over.
844
00:38:17,729 --> 00:38:22,019
So Swift data, I, to me, I don't
know of anything special about
845
00:38:22,019 --> 00:38:23,749
it that changes dependencies.
846
00:38:23,749 --> 00:38:26,089
I mean, the most special
thing about it is just.
847
00:38:26,524 --> 00:38:29,794
of how it plays nicely with SwiftUI,
like when, because you know,
848
00:38:29,794 --> 00:38:35,044
historically, if you threw a reference
type into a SwiftUI view just in the
849
00:38:35,044 --> 00:38:38,554
most naive way, none of its changes
would cause updates to the view.
850
00:38:38,554 --> 00:38:41,574
And now we've got the machinery that
allows you to throw in a reference type,
851
00:38:41,814 --> 00:38:45,224
and you make a mutation to something,
and it does update the SwiftUI view.
852
00:38:45,274 --> 00:38:48,274
So that is big, and I think
that will be highly applicable.
853
00:38:48,589 --> 00:38:52,039
Outside of Swift data
and observable objects.
854
00:38:52,039 --> 00:38:56,639
I think you will be able to you could
have the idea of a, at one of our at
855
00:38:56,639 --> 00:39:00,279
dependency property wrappers could
potentially hook into that so that
856
00:39:00,279 --> 00:39:01,709
you could actually
use it in the view.
857
00:39:01,719 --> 00:39:04,629
Whereas typically right now you use it
in the observable object or the view
858
00:39:04,629 --> 00:39:07,929
controller, but there are other places
I think you could start using it.
859
00:39:08,409 --> 00:39:08,629
Yeah.
860
00:39:09,629 --> 00:39:11,429
Leo Dion (host): Anything else you
want to mention before we close out?
861
00:39:11,459 --> 00:39:14,189
Any sneak previews of
new point free stuff?
862
00:39:14,819 --> 00:39:16,419
Brandon Williams (guest):
Yeah, I mean, let's see today.
863
00:39:16,859 --> 00:39:18,959
So next week we're releasing 1.
864
00:39:18,959 --> 00:39:21,189
0 of the composable architecture.
865
00:39:21,229 --> 00:39:23,369
It's been in development for four years.
866
00:39:23,719 --> 00:39:25,979
And so that's a big release.
867
00:39:26,029 --> 00:39:29,239
And yeah, all the observation
and macro stuff, it really
868
00:39:29,239 --> 00:39:31,469
fundamentally changes so much of what.
869
00:39:31,874 --> 00:39:34,064
We've always wanted to do with
the composable architecture and
870
00:39:34,064 --> 00:39:35,234
what wasn't really possible.
871
00:39:35,234 --> 00:39:37,124
And so there's a lot of big stuff there.
872
00:39:37,174 --> 00:39:40,524
And yeah, we've got this Swift
dependencies library just github.
873
00:39:40,524 --> 00:39:43,544
com slash pointfreeco
slash swift dependencies.
874
00:39:43,564 --> 00:39:47,384
And it's, and there, and we've got
links in the readme to all the other
875
00:39:47,424 --> 00:39:48,524
dependency libraries out there.
876
00:39:48,534 --> 00:39:51,365
Cause I am in no way saying
people should go and use ours.
877
00:39:51,365 --> 00:39:55,164
Like we, we have made some very
particular decisions in the
878
00:39:55,164 --> 00:39:56,334
design of our library that.
879
00:39:56,679 --> 00:39:59,289
Makes it so that we can't even
do some of the things that
880
00:39:59,289 --> 00:40:00,559
the other libraries can do.
881
00:40:00,819 --> 00:40:03,729
But then, on the flip side, is that we
can do some things that they can't do.
882
00:40:03,729 --> 00:40:05,429
It's just, there's tradeoffs
all over the place.
883
00:40:05,669 --> 00:40:07,959
And I highly recommend people
go look at those libraries.
884
00:40:07,989 --> 00:40:10,009
But yeah, we've got our
own version of the library.
885
00:40:10,469 --> 00:40:11,219
And yeah.
886
00:40:11,329 --> 00:40:12,429
I encourage people to check it out.
887
00:40:13,299 --> 00:40:14,899
Leo Dion (host): Brandon, thank
you so much for coming on.
888
00:40:14,899 --> 00:40:15,809
It was great to have you.
889
00:40:16,459 --> 00:40:17,869
Where can people find you online?
890
00:40:18,789 --> 00:40:23,979
Brandon Williams (guest): Yeah it's
MbrandenW on Twitter and then also on
891
00:40:23,989 --> 00:40:27,089
Mastodon on the Hackaderm instance.
892
00:40:27,139 --> 00:40:27,299
Leo Dion (host): Yeah.
893
00:40:27,299 --> 00:40:27,539
Yeah.
894
00:40:27,919 --> 00:40:28,409
Awesome.
895
00:40:28,409 --> 00:40:31,969
And then of course, point free
we'll have links to that as well.
896
00:40:32,449 --> 00:40:34,629
People can find me on
Twitter at Leo G Dion.
897
00:40:34,629 --> 00:40:36,009
My company is bright digit.
898
00:40:36,359 --> 00:40:38,669
If you're watching this on
YouTube, please and subscribe.
899
00:40:38,669 --> 00:40:41,589
If you're listening to
this, please post a review.
900
00:40:41,929 --> 00:40:43,399
Thank you so much for joining us.
901
00:40:43,419 --> 00:40:45,939
And I look forward to
talking to everyone again.
902
00:40:46,069 --> 00:40:46,639
Bye everyone.
903
00:40:47,209 --> 00:40:47,479
Brandon Williams (guest): Thanks.
904
00:40:47,709 --> 00:40:47,909
Bye.