-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathFriday Session 1. Debugging and Xcode Tips and Tricks.srt
executable file
·3536 lines (2800 loc) · 71.3 KB
/
Friday Session 1. Debugging and Xcode Tips and Tricks.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1
00:00:00,267 --> 00:00:04,603
[MUSIC]
2
00:00:04,672 --> 00:00:07,372
Stanford University.
3
00:00:07,441 --> 00:00:08,940
>> Alrighty, well,
hi everybody.
4
00:00:09,009 --> 00:00:11,176
My name is Jason.
I'm one of your two TAs.
5
00:00:11,178 --> 00:00:13,412
Junjie is the other one.
She is not here today and
6
00:00:13,414 --> 00:00:13,445
we are gonna go over today
kinda two different things.
7
00:00:14,515 --> 00:00:17,249
we are gonna go over today
kinda two different things.
8
00:00:17,317 --> 00:00:19,818
One is just a whirlwind tour
of Xcode just to make your
9
00:00:19,886 --> 00:00:21,353
life a lot simpler for
the entire quarter and
10
00:00:21,421 --> 00:00:23,856
the rest of your life to make
it more familiar to you.
11
00:00:23,924 --> 00:00:26,391
And the other thing is how to
use the debugger within Xcode
12
00:00:26,460 --> 00:00:27,426
in particular.
13
00:00:29,830 --> 00:00:31,830
than most sections just cuz
there's not that much material
14
00:00:31,899 --> 00:00:33,965
to get through, so we'll
be out of here a bit early.
15
00:00:34,034 --> 00:00:35,867
But um, there is also,
there is also no slides or
16
00:00:35,936 --> 00:00:37,803
anything like that,
there is no lecture to give,
17
00:00:37,871 --> 00:00:39,871
it's just I'm gonna hop
right into the demo.
18
00:00:39,940 --> 00:00:42,107
And feel free to stop me
at any point, just shout,
19
00:00:42,175 --> 00:00:44,009
raise your hand if something
is not clear if you wanna,
20
00:00:44,078 --> 00:00:46,110
you wanna learn more about
something or whatever, and
21
00:00:46,179 --> 00:00:47,412
I'll stop to do that.
22
00:00:47,481 --> 00:00:49,414
I know we're going through
a giant list of key commands.
23
00:00:49,483 --> 00:00:50,983
It's not like the most
engaging lecture, so
24
00:00:51,051 --> 00:00:52,850
I'll try to be as
engaging as possible, but
25
00:00:52,919 --> 00:00:54,786
uh, it is actually
super useful.
26
00:00:54,855 --> 00:00:56,922
So if, if I want you to have
like one take away from,
27
00:00:56,991 --> 00:00:59,757
from this whole talk, it's
that, if you wanna get good at
28
00:00:59,826 --> 00:01:01,893
using Xcode and you wanna feel
fluent when you're using it,
29
00:01:01,962 --> 00:01:04,096
you actually need to know
a lot of key commands.
30
00:01:04,164 --> 00:01:05,330
It will really help you a lot.
31
00:01:07,668 --> 00:01:09,968
Xcode from Paul in lectures
but actually learning all the
32
00:01:10,037 --> 00:01:12,437
shortcuts for everything will
make your life way simpler.
33
00:01:12,506 --> 00:01:14,339
And I hope I can kinda
convince you today that all
34
00:01:14,408 --> 00:01:16,208
this stuff is actually
pretty intuitive.
35
00:01:16,276 --> 00:01:18,276
It's not just like memorizing
a bunch of random things, but
36
00:01:18,345 --> 00:01:20,678
it's all laid out by Apple
in a very nice and, and
37
00:01:20,747 --> 00:01:21,346
orderly way.
38
00:01:23,717 --> 00:01:25,651
So let's just dive right in.
39
00:01:25,719 --> 00:01:29,287
I'm gonna pop up an Xcode here
and I have Concentration open,
40
00:01:29,356 --> 00:01:31,856
which is the end of
Wednesday's lecture,
41
00:01:31,925 --> 00:01:33,392
we had this code working.
42
00:01:33,460 --> 00:01:36,761
The catch here though is that
this version of Concentration
43
00:01:36,830 --> 00:01:40,399
that I'm using right now, I've
deemed it sad Concentration.
44
00:01:40,467 --> 00:01:41,433
You can see right
here on this folder,
45
00:01:43,470 --> 00:01:45,971
we're gonna investigate
that using the debugger.
46
00:01:46,039 --> 00:01:48,039
But before we do that,
I am gonna hop in and
47
00:01:48,108 --> 00:01:51,309
give you a tour of Xcode using
key commands and what not.
48
00:01:51,378 --> 00:01:54,713
So you remember things from
lecture where you've seen for
49
00:01:54,782 --> 00:01:56,415
example, you can navigate
around all the panes
50
00:01:56,484 --> 00:01:58,583
by clicking these various
buttons, but it's gonna
51
00:01:58,652 --> 00:02:00,318
get really old really
fast when you're coding.
52
00:02:00,387 --> 00:02:00,886
If you're also
53
00:02:02,989 --> 00:02:04,823
You can get like five
times faster if you just
54
00:02:06,493 --> 00:02:08,159
learn how things are laid
out in some various things.
55
00:02:08,228 --> 00:02:10,228
So the first thing,
I'll just kinda go,
56
00:02:10,297 --> 00:02:12,497
go through Xcode in order,
kinda from the top left.
57
00:02:12,566 --> 00:02:15,767
The first thing is, all this
stuff up here at the top left,
58
00:02:15,836 --> 00:02:17,836
you can actually do
automated by key commands.
59
00:02:17,905 --> 00:02:20,371
So instead of going up and
clicking Run and what not,
60
00:02:20,440 --> 00:02:22,374
you can do Cmd+R,
and that will run.
61
00:02:24,912 --> 00:02:26,110
So there,
there are key commands for
62
00:02:26,179 --> 00:02:28,246
controlling everything about
running and, and stopping and
63
00:02:28,315 --> 00:02:29,515
all that stuff.
64
00:02:29,583 --> 00:02:32,184
Um, the next thing I wanna
talk about is more important
65
00:02:32,252 --> 00:02:35,487
which is just how you actually
navigate around all of Xcode.
66
00:02:35,555 --> 00:02:38,657
And so there are key commands
for doing things like, if you
67
00:02:38,725 --> 00:02:41,927
watch the screen right now,
I can do this, this, this.
68
00:02:43,597 --> 00:02:45,063
You get really fast
at this stuff.
69
00:02:46,867 --> 00:02:49,334
We're, were opening up
a second editor right now.
70
00:02:50,503 --> 00:02:50,936
Right, so
71
00:02:53,473 --> 00:02:55,840
how you can like quickly
get your way around Xcode.
72
00:02:55,909 --> 00:02:59,144
So when I close everything
that I just did.
73
00:02:59,213 --> 00:03:01,513
Suppose that were at a full
main screen like this,
74
00:03:01,582 --> 00:03:03,982
the way that everything is
laid out is very logical,
75
00:03:04,051 --> 00:03:06,852
where the left-most pane,
which is called the Navigator,
76
00:03:06,920 --> 00:03:08,152
is controlled by Cmd+0.
77
00:03:08,221 --> 00:03:10,688
That's what shows it.
78
00:03:10,757 --> 00:03:14,692
And then the right-most pane
is showed using Cmd+Option+0.
79
00:03:14,761 --> 00:03:18,130
That's what shows and
hides the op, right-most pane.
80
00:03:18,198 --> 00:03:21,633
And then within each pane,
so if I'm on the left pane,
81
00:03:21,702 --> 00:03:25,837
if I do Cmd+1,2,3,4,5 you see
how up on the top left here
82
00:03:25,906 --> 00:03:28,072
we're going through
these tabs?
83
00:03:28,141 --> 00:03:30,976
1, 2, 3, 4, 5, right?
84
00:03:31,045 --> 00:03:33,011
And then if I do Cmd+Option+0,
and
85
00:03:33,079 --> 00:03:36,414
I look at these tabs up here,
I just do Cmd+Option+1, 2 and
86
00:03:36,483 --> 00:03:38,950
I can go through
all those tabs.
87
00:03:39,019 --> 00:03:40,686
So it's actually pretty
nicely laid out like that.
88
00:03:40,754 --> 00:03:43,287
You just remember that, Cmd+0
is for showing and hiding and
89
00:03:43,356 --> 00:03:44,623
then the numbers are for
tabbing.
90
00:03:44,691 --> 00:03:47,058
And then if you add in Option,
it does the right side.
91
00:03:47,127 --> 00:03:48,560
So it's pretty simple.
92
00:03:48,628 --> 00:03:52,464
If you just do Cmd+Shift+y,
it toggles the console and
93
00:03:52,532 --> 00:03:56,168
the debugger at the bottom
which we'll be working with
94
00:03:56,236 --> 00:03:57,469
more later today.
95
00:03:57,538 --> 00:03:59,504
And those commands alone are
enough to just kind of like
96
00:03:59,573 --> 00:04:00,939
constantly manage
your window size,
97
00:04:01,008 --> 00:04:02,874
especially if you're
programming on a laptop where
98
00:04:02,943 --> 00:04:04,676
you only have like limited
screen real estate.
99
00:04:04,745 --> 00:04:07,812
It's actually really nice to
be able to use those commands
100
00:04:07,881 --> 00:04:09,881
to quickly navigate around.
101
00:04:09,949 --> 00:04:12,717
The next thing I'll point out
is that, you know from lecture
102
00:04:12,786 --> 00:04:15,687
that Xcode has uh,
two different editors.
103
00:04:15,755 --> 00:04:18,757
It has the um, the main editor
that we' re in right here, and
104
00:04:18,826 --> 00:04:21,726
it has also this thing
called the assistant editor.
105
00:04:21,795 --> 00:04:27,132
So if we do
a Cmd+Option+Enter.
106
00:04:27,201 --> 00:04:29,834
It pops up in this second
pane over here, and
107
00:04:29,903 --> 00:04:33,171
then we can do Cmd+Enter to
go back to just one pane, so
108
00:04:33,240 --> 00:04:35,207
this is super useful.
109
00:04:35,275 --> 00:04:37,842
The one thing that I'll point
out about this is that,
110
00:04:37,911 --> 00:04:41,380
if you go to your,
your Xcode preferences window,
111
00:04:41,448 --> 00:04:43,949
we have all these things that
we can, that we can toggle and
112
00:04:44,017 --> 00:04:44,549
we won't go through all
113
00:04:46,519 --> 00:04:47,919
You can go around and
change your font colors and
114
00:04:47,988 --> 00:04:49,054
all that good stuff.
115
00:04:51,658 --> 00:04:54,559
recommend that you utilize,
which is in Navigation here.
116
00:04:54,628 --> 00:04:57,896
There's this little check box
that says, Navigation uses
117
00:04:57,965 --> 00:05:01,199
the primary editor, versus
using the focused editor, and
118
00:05:01,268 --> 00:05:04,235
by default, this is set to
using the primary editor.
119
00:05:04,304 --> 00:05:07,539
And that's going to probably
torture you if you use certain
120
00:05:07,608 --> 00:05:09,006
other key commands.
121
00:05:09,075 --> 00:05:10,542
Let me give you an example.
122
00:05:10,610 --> 00:05:13,511
One of the key commands is for
opening certain files without
123
00:05:13,580 --> 00:05:15,146
having to navigate
there in the,
124
00:05:15,215 --> 00:05:16,815
in the file
navigator over here.
125
00:05:16,883 --> 00:05:19,450
So let's say that I,
we all know that there's
126
00:05:19,519 --> 00:05:22,454
a file called Card.swift and
we wanna open it, all I
127
00:05:22,523 --> 00:05:25,490
have to do is Cmd+Shift+O for
open, type card, and
128
00:05:25,559 --> 00:05:29,327
then there's Card.swift,
and that will open it up.
129
00:05:29,396 --> 00:05:30,128
Now what if I wanted
130
00:05:32,900 --> 00:05:35,199
So right here,
I am zooming around in the,
131
00:05:35,268 --> 00:05:37,268
in the right pane and I have
the right pane selected.
132
00:05:37,337 --> 00:05:39,670
If I do Cmd+Shift+O and
I go back to ViewController,
133
00:05:39,739 --> 00:05:42,707
it still opens in
the left pane.
134
00:05:42,775 --> 00:05:45,309
So if you don't have this use
focused editor option selected
135
00:05:45,378 --> 00:05:47,378
it's always going to
use the left editor or
136
00:05:47,447 --> 00:05:49,180
the prime editor for
those key commands.
137
00:05:49,249 --> 00:05:52,150
So that's why you wanna have
this box checked, so that now
138
00:05:52,218 --> 00:05:55,086
when we go over here and
we have the right one selected
139
00:05:55,155 --> 00:05:57,655
and we do card, it opens
it over on the right pan.
140
00:05:57,724 --> 00:05:58,990
Makes sense?
141
00:05:59,059 --> 00:06:02,526
Cool, so I highly
recommend that you do that.
142
00:06:02,595 --> 00:06:05,596
Okay, the next thing,
we're gonna do is actually
143
00:06:05,665 --> 00:06:08,566
talk about text editing within
each window really briefly.
144
00:06:08,635 --> 00:06:11,369
One thing that I wanna point
out is, you haven't dealt with
145
00:06:11,437 --> 00:06:14,038
this problem yet because your
Xcode projects haven't gotten
146
00:06:14,107 --> 00:06:15,907
very large, but
they will get very large.
147
00:06:15,976 --> 00:06:17,241
There will be lots
of code files and
148
00:06:17,310 --> 00:06:19,344
eventually you'll have
hundreds of files in a single
149
00:06:19,413 --> 00:06:21,579
project when you're making
a big Xcode project.
150
00:06:21,648 --> 00:06:24,682
And one of the things that
will help you navigate that is
151
00:06:24,751 --> 00:06:27,452
to help yourself by
leaving Navigation,
152
00:06:27,521 --> 00:06:30,688
like Navigation helper things
throughout your files and
153
00:06:30,757 --> 00:06:33,524
one way to do that is this
comment right here that is
154
00:06:33,593 --> 00:06:35,259
prefixed with comment mark.
155
00:06:35,295 --> 00:06:35,326
excuse me.
156
00:06:37,731 --> 00:06:38,363
below this line.
157
00:06:41,134 --> 00:06:43,535
this notification in
this window up here.
158
00:06:43,604 --> 00:06:44,936
That's where card
touch behavior is and
159
00:06:45,004 --> 00:06:46,270
it will jump to that
point of the file.
160
00:06:46,339 --> 00:06:48,306
And so you can imagine in big
files, using these marks is
161
00:06:48,375 --> 00:06:50,241
actually super helpful
when they're really long,
162
00:06:50,309 --> 00:06:51,543
something to navigate around.
163
00:06:53,313 --> 00:06:56,013
The next thing that I'll point
out about text editing is,
164
00:06:56,082 --> 00:06:58,850
it's very useful just to know
basic text editing commands.
165
00:06:58,919 --> 00:07:01,386
Like for example, if you
have many lines selected and
166
00:07:01,454 --> 00:07:03,821
you want to comment them
out all of a sudden,
167
00:07:03,890 --> 00:07:07,758
just Cmd+/ will comment
things out like that and
168
00:07:07,827 --> 00:07:10,295
then Cmd+/ again
will undo them.
169
00:07:10,363 --> 00:07:12,897
Another maybe even more useful
thing is when you get yourself
170
00:07:12,966 --> 00:07:15,100
into a,
a nasty state like this.
171
00:07:17,070 --> 00:07:19,437
Just mess some stuff up for
no reason.
172
00:07:19,506 --> 00:07:21,372
And you can tell that it's
really not formatted.
173
00:07:21,441 --> 00:07:23,074
We can select everything
that we want and
174
00:07:23,143 --> 00:07:25,743
do Ctrl+I, I for
indent and it will just
175
00:07:25,812 --> 00:07:28,179
magically put everything
exactly like we wanted.
176
00:07:28,248 --> 00:07:29,747
So that'll save you a lot
of time and headache,
177
00:07:29,816 --> 00:07:31,516
if things are not, if you,
178
00:07:31,585 --> 00:07:33,951
if you can't tell things that
are nicely indented or not.
179
00:07:34,020 --> 00:07:36,054
And I'll list these all
online on Piazza by the way,
180
00:07:36,122 --> 00:07:37,922
so it's not like you need
to know down what they are.
181
00:07:37,991 --> 00:07:39,324
I just kinda want
to give you the,
182
00:07:39,393 --> 00:07:41,426
give you the lay
of the land here.
183
00:07:41,495 --> 00:07:43,795
So hopefully we're through
the, the fast sorta boring
184
00:07:43,863 --> 00:07:46,364
part of the lecture where it's
just all of the key commands.
185
00:07:46,433 --> 00:07:48,199
But I highly recommend that
you learn all this stuff and
186
00:07:48,267 --> 00:07:49,967
start getting it into
your muscle memory so
187
00:07:50,036 --> 00:07:51,436
that when you're
navigating on Xcode,
188
00:07:51,505 --> 00:07:54,206
you're not torturing yourself
for having to click around
189
00:07:54,274 --> 00:07:56,941
everywhere and
do everything manually.
190
00:07:57,010 --> 00:07:59,277
The next thing to do is
to actually start using
191
00:07:59,346 --> 00:08:00,111
the debugger.
192
00:08:02,416 --> 00:08:04,449
we're not actually using
the version of concentration
193
00:08:04,518 --> 00:08:06,284
directly from the end
of Wednesday's lecture.
194
00:08:06,353 --> 00:08:08,587
We're actually using a
slightly broken version of it,
195
00:08:08,655 --> 00:08:11,088
and so let's see what happens
when we actually run this one.
196
00:08:11,157 --> 00:08:13,991
I'm gonna run it on
the iPhone X simulator using
197
00:08:14,060 --> 00:08:17,929
our trusty Cmd+R key command,
and let's see what happens.
198
00:08:30,043 --> 00:08:32,843
So I've crashed, it doesn't
even work right from
199
00:08:32,912 --> 00:08:35,747
the start, and we're thrown
to the app delegate,
200
00:08:35,815 --> 00:08:37,515
which is the main file.
201
00:08:37,584 --> 00:08:39,551
It's crashing on the main
method it says, but
202
00:08:39,619 --> 00:08:40,785
that's not very helpful.
203
00:08:40,854 --> 00:08:43,021
So the way that we first
get more insight into this,
204
00:08:43,090 --> 00:08:44,756
is to look into
the actual stack trace,
205
00:08:44,824 --> 00:08:46,691
which shows up in
the console log down here.
206
00:08:46,760 --> 00:08:48,325
And you just see this
huge stack trace,
207
00:08:48,394 --> 00:08:50,361