-
Notifications
You must be signed in to change notification settings - Fork 0
/
10. Core Data.srt
10414 lines (8332 loc) · 242 KB
/
10. Core Data.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,401 --> 00:00:04,535
[MUSIC]
(音乐)
2
00:00:04,604 --> 00:00:07,838
Stanford University,
斯坦福大学,
3
00:00:07,907 --> 00:00:11,109
>> All right, well, welcome to Stanford CS193P,
> >好吧,好吧,欢迎来到斯坦福CS193P,
4
00:00:11,177 --> 00:00:16,980
This is Developing iOS Application, Winter of 2017,
这是开发iOS应用程序,2017年冬天,
5
00:00:17,049 --> 00:00:19,983
And the only topic for today is a big one, Core Data,
唯一的今天是一个大主题,核心数据,
6
00:00:20,052 --> 00:00:23,019
which is an object oriented database,
这是一个面向对象的数据库,
7
00:00:23,088 --> 00:00:24,821
But before I dive into this,
但在我深入之前,
8
00:00:24,889 --> 00:00:28,324
I'm actually going to revisit that demo we did last time
我要重新审视我们上次演示
9
00:00:28,393 --> 00:00:31,260
just briefly, because we ran out of time and so
只是短暂的,因为我们跑的时间
10
00:00:31,329 --> 00:00:34,262
I wasn't able to show you the refresh control,
我无法给你刷新控制,
11
00:00:34,331 --> 00:00:35,797
Now I posted the code for it, so
现在我发布的代码,所以
12
00:00:35,866 --> 00:00:38,066
I'm not gonna type all the code in here,
我不会输入所有的代码在这里,
13
00:00:38,134 --> 00:00:40,701
But I'm just gonna briefly show you
但是我要简要地告诉你
14
00:00:40,770 --> 00:00:43,270
how that refresh control worked, okay?
刷新控制是怎样工作的,好吗?
15
00:00:43,339 --> 00:00:45,171
Okay, so we missed that,
好的,我们错过了,
16
00:00:45,240 --> 00:00:47,907
So here is the app we had from last time,
这是应用程序从上次我们有,
17
00:00:47,976 --> 00:00:50,977
By the way, I have modified our app
顺便说一下,我修改了我们的应用程序
18
00:00:51,046 --> 00:00:53,045
here to change our request a little bit,
这一点,改变我们的要求
19
00:00:53,113 --> 00:00:55,347
If you remember this line of code from last time,
如果你还记得这行代码从最后一次,
20
00:00:55,416 --> 00:00:56,815
it used to just have the query,
以前只有查询,
21
00:00:56,884 --> 00:01:00,718
But I've changed it to also filter out retweets and
但是我已经改变了它也过滤掉转发
22
00:01:00,787 --> 00:01:04,188
I've also put on the safe filter, which hopefully will
我也戴上安全过滤器,这有望
23
00:01:04,257 --> 00:01:06,624
make it so that when I do these look ups,
让它这样,当我做这些,
24
00:01:06,692 --> 00:01:10,227
these sort of up looks, we don't get stuff on the screen,
这些看起来,我们没有得到的东西在屏幕上,
25
00:01:10,296 --> 00:01:12,129
you know this is a family show,
你知道这是一个家庭,
26
00:01:12,197 --> 00:01:15,331
so we don't want to see some of that stuff,
所以我们不想看到一些东西,
27
00:01:15,400 --> 00:01:17,666
Anyway, hopefully, that'll work,
无论如何,希望,可以工作,
28
00:01:17,735 --> 00:01:19,735
So let's go back here and
那么让我们回到这里
29
00:01:19,804 --> 00:01:22,571
take a look at what this looks like,
看看这是什么样子,
30
00:01:22,640 --> 00:01:24,272
There's my simulator right here,
这里有我的模拟器,
31
00:01:24,341 --> 00:01:25,273
So let's go ahead and search,
让我们继续搜索,
32
00:01:25,341 --> 00:01:29,710
Let's try Trump again and cross our fingers, all right,
让我们再次尝试Trump和交叉手指,好吧,
33
00:01:29,779 --> 00:01:34,949
So that's not, I don't see anything too terrible there,
所以这不是,我没有看到任何太可怕了,
34
00:01:35,017 --> 00:01:38,752
Okay so what we added was this UI where we can pull down,
所以我们添加这个UI可以拉下来,
35
00:01:38,821 --> 00:01:40,153
Okay and it adds more tweets,
好的,它增加了更多的推文谈及这次慈善拍卖,
36
00:01:40,221 --> 00:01:41,888
you see how it added a tweet there?
你看看它添加了一个推特吗?
37
00:01:41,957 --> 00:01:43,589
We have the second pull right there,
我们有第二个拉,
38
00:01:43,658 --> 00:01:44,724
this was with the first pull,
这是第一次拉,
39
00:01:44,792 --> 00:01:49,895
And we pull down again, no tweets this time, okay?
我们拉下来,不推这一次,好吗?
40
00:01:49,964 --> 00:01:52,431
So each time we pull down it's doing another twitter
所以每次我们拆掉做另一个twitter
41
00:01:52,499 --> 00:01:53,497
fetch, and
取回,
42
00:01:53,566 --> 00:01:57,268
may get more tweets depending if people are tweeting or not,
可能获得更多的tweet是否人发微博,
43
00:01:57,337 --> 00:01:59,503
So let's take a look at the code to do this, again,
让我们看一看代码要做到这一点,再一次,
44
00:01:59,572 --> 00:02:01,004
I posted this code, but
我发布了这段代码,但
45
00:02:01,073 --> 00:02:02,539
we'll just look at it, I'm not gonna type it all in,
我们将看看它,我不会在类型,
46
00:02:02,608 --> 00:02:04,207
we're just gonna look at it real quick,
我们要看它很快,
47
00:02:04,275 --> 00:02:07,042
First of all, let's talk about how do I get this UI where
首先,让我们谈谈我怎么得到这个UI
48
00:02:07,111 --> 00:02:11,280
we pull down and it calls a method, or whatever?
我们拉下,它调用一个方法,或任何?
49
00:02:11,349 --> 00:02:14,150
So let's go to look in our storyboard,
让我们去看看我们的故事板,
50
00:02:16,854 --> 00:02:19,787
All right, so here's our storyboard, and
好吧,这是我们的故事板
51
00:02:19,856 --> 00:02:23,691
what I did was I just selected my table view controller and
我所做的是我只是选择我的表视图控制器和
52
00:02:23,760 --> 00:02:26,193
I went down here to this refreshing,
我去下面这个让人耳目一新,
53
00:02:26,262 --> 00:02:27,360
You see that refreshing choice?
你会看到令人耳目一新的选择?
54
00:02:27,429 --> 00:02:30,864
And I changed it from disabled to enabled, and when I set it
我改变它从禁用启用,当我把它
55
00:02:30,933 --> 00:02:33,466
to enabled nothing changed here in the UI,
启用任何UI,这里发生了巨大的变化
56
00:02:33,535 --> 00:02:36,436
You can't see any spinning thing, but
你不能看到任何旋转的事情,但是
57
00:02:36,504 --> 00:02:40,072
over here in the document outline it created this
在创建这个文档大纲
58
00:02:40,141 --> 00:02:42,340
refresh control right here,
刷新控制这里,
59
00:02:42,409 --> 00:02:45,977
And so I can control drag from the document outline just as I
所以我可以控制文档大纲正如我的阻力
60
00:02:46,046 --> 00:02:47,145
can through here,
可以在这里通过,
61
00:02:47,214 --> 00:02:49,680
So all I did to make this work is I just brought up
所以我所做的这个工作是我长大的
62
00:02:49,749 --> 00:02:52,082
my controller right here,
我的控制器,
63
00:02:52,151 --> 00:02:53,784
And here's the method I did it with right here,
这是我用的方法,
64
00:02:53,853 --> 00:02:58,188
I just Ctrl dragged from the Refresh Control to this method
我刚从刷新控制Ctrl拖这个方法
65
00:02:58,256 --> 00:03:00,590
called refresh, okay?
称为刷新?
66
00:03:00,659 --> 00:03:04,360
That's all I did to, to make that happen,
这就是我所做的,让这发生,
67
00:03:04,429 --> 00:03:05,627
And inside refresh,
在刷新,
68
00:03:05,696 --> 00:03:08,363
I just called that same method I had before, searchForTweets,
我叫同样的方法之前,searchForTweets,
69
00:03:08,432 --> 00:03:10,698
This one right here, the one that search for tweets,
这一个在这里,一个搜索微博,
70
00:03:10,767 --> 00:03:12,533
And that used to look like this,
这是这个样子,
71
00:03:12,602 --> 00:03:14,368
I only changed one thing in here,
在这里我只改变一件事,
72
00:03:14,437 --> 00:03:17,805
It used to just get the twitterRequest by
过去把twitterRequest
73
00:03:17,873 --> 00:03:19,873
looking at our search term up here,
看着我们的搜索词,
74
00:03:19,942 --> 00:03:21,475
Remember this function?
还记得这个函数吗?
75
00:03:21,543 --> 00:03:25,144
And all I did was added this, which says, if
和我所做的只是增加了这个,说,如果
76
00:03:25,213 --> 00:03:29,849
the lastTwitterRequest has a newer version, then use that,
lastTwitterRequest有新版本,然后使用,
77
00:03:29,918 --> 00:03:33,319
But if it doesn't, then default back to doing to query
但如果没有,那么默认的回做查询
78
00:03:33,388 --> 00:03:35,053
request the way we used to,
要求我们使用的方式,
79
00:03:35,122 --> 00:03:37,355
The only other things that I had to do was turn the refresh
唯一的其他事情,我要做的就是把刷新
80
00:03:37,424 --> 00:03:39,524
control off, you do that with the end refreshing,
控制了,你刷新,
81
00:03:39,593 --> 00:03:42,159
So I just did that when I went back to the main queue here,
所以我就做了,当我回到这里的主要队列,
82
00:03:42,228 --> 00:03:44,328
to get my results, so I turned it off,
我的结果,所以我关闭它,
83
00:03:44,397 --> 00:03:45,562
I also turned it off if for
如果对我也关掉它
84
00:03:45,631 --> 00:03:48,265
some reason I couldn't get any request or whatsoever,
某些原因,我不能得到任何请求或,
85
00:03:48,333 --> 00:03:50,634
Okay, there's nothing in the search term field and
好的,没有什么在搜索领域
86
00:03:50,702 --> 00:03:53,002
I couldn't get a newer version of my last request,
我不能得到一个新版本的我最后的请求,
87
00:03:53,071 --> 00:03:55,771
So I just said, I'm gonna make sure that thing is not
所以我就说,不是我要确保那件事
88
00:03:55,840 --> 00:03:57,940
spinning and spinning forever,
永远旋转和旋转,
89
00:03:58,009 --> 00:03:59,374
They wanna get out of here with that,
他们想离开这里,
90
00:03:59,443 --> 00:04:02,110
And the only other thing I had to do was up here,
唯一的另一件事我要做的就是,
91
00:04:02,178 --> 00:04:05,813
when the search text changes, someone types#Stanford or
当搜索文本变化时,有人#斯坦福或类型
92
00:04:05,882 --> 00:04:09,250
something like that, I need to invalidate that last Twitter
这样,我需要最后一个Twitter失效
93
00:04:09,318 --> 00:04:12,152
request so that it's not trying to get new versions
请求,不是为了得到新版本
94
00:04:12,221 --> 00:04:13,920
of the previous one that I had,
以前的我,
95
00:04:13,989 --> 00:04:16,589
I want it to do the new one,
我想要做新的,
96
00:04:16,658 --> 00:04:20,226
And the way that I made it so that we had these little
和我做了这样的方式我们有这些小
97
00:04:20,295 --> 00:04:24,296
titles right here, see these titles two, three, four, five?
标题在这里,看到这些标题两个,三个,四个,五个?
98
00:04:24,365 --> 00:04:27,132
I implemented another UI table view data source method,
我另一个数据源中方法实现的,
99
00:04:27,201 --> 00:04:28,900
this one down here,
是下面这个,
100
00:04:28,969 --> 00:04:31,203
Called titleForHeaderInSection,
叫titleForHeaderInSection,
101
00:04:31,271 --> 00:04:33,437
I just put titles on the sections,
我把标题部分,
102
00:04:33,506 --> 00:04:36,974
Remember, each section is another pull from Twitter,
记住,每个部分是另一个来自Twitter的拉,
103
00:04:37,043 --> 00:04:38,642
And so I just have each title,
所以我只有每个标题,
104
00:04:38,711 --> 00:04:41,377
It's actually gonna be the count of things I had minus
其实要计数的事情我已经减去
105
00:04:41,446 --> 00:04:42,312
the section number,
节数,
106
00:04:42,381 --> 00:04:44,146
So the top one is section zero,
上面部分是零,
107
00:04:44,215 --> 00:04:45,814
So section zero is gonna show
所以部分会显示为零
108
00:04:45,883 --> 00:04:47,115
the number of pulls that I've made,
拉我的数量,
109
00:04:47,184 --> 00:04:48,516
tweets,count is how many pulls I made,
微博,数量是多少,
110
00:04:48,585 --> 00:04:50,151
And it's obviously gonna
这显然会
111
00:04:50,219 --> 00:04:51,853
decrement as the sections go down,
部分向下递减,
112
00:04:54,123 --> 00:04:57,391
Okay, so that's what gave us this,
好了,这就是给我们,
113
00:04:57,460 --> 00:04:58,892
And you can see that the longer we wait,
你可以看到,我们等待的时间越长,
114
00:04:58,961 --> 00:05:01,661
obviously it pulls more information,
很显然,把更多的信息。
115
00:05:01,730 --> 00:05:02,829
as tweets pile up,
随着微博的堆积,
116
00:05:04,331 --> 00:05:08,334
Okay, let's go back to our slides,
好的,让我们回到我们的幻灯片,
117
00:05:08,402 --> 00:05:10,202
All right, here we go,
好吧,我们开始吧,
118
00:05:10,271 --> 00:05:13,871
So Core Data is this big framework inside of iOS for
这是核心数据iOS的大框架内
119
00:05:13,940 --> 00:05:16,574
doing object-oriented databases,
做面向对象数据库,
120
00:05:16,643 --> 00:05:19,409
So let's talk a little bit about what that means,
让我们讨论一下这意味着什么,
121
00:05:19,478 --> 00:05:21,545
So, when do you need a database?
所以,当你需要一个数据库吗?
122
00:05:21,613 --> 00:05:23,814
Well you need a database when you have a large amount of
你需要一个当你有大量的数据库
123
00:05:23,882 --> 00:05:26,916
data, and especially if you want to kind of make queries
数据,尤其是如果你想查询
124
00:05:26,985 --> 00:05:30,153
into that data and find out things about that data and
到数据,找出数据和事情
125
00:05:30,221 --> 00:05:32,654
the relationships between all the things in there,
之间的关系的所有事情,
126
00:05:32,723 --> 00:05:34,089
You really can't do that by like,
你真的不能通过,
127
00:05:34,158 --> 00:05:36,558
taking a big dictionary or a big array and
大字典或大数组和
128
00:05:36,627 --> 00:05:39,627
searching through it, you need a database,
搜索通过它,你需要一个数据库,
129
00:05:39,696 --> 00:05:42,797
And so there's a lot of technologies for databases out
所以有很多的数据库技术
130
00:05:42,866 --> 00:05:45,766
there but most of them are not object-oriented,
但他们中的大多数并不是面向对象的,
131
00:05:45,835 --> 00:05:48,769
So we have this framework that Apple provides called
所以我们有这个框架,苹果提供了
132
00:05:48,837 --> 00:05:51,705
Core Data, it's what we call an object-oriented database
核心数据,这就是我们所说的一个面向对象的数据库
133
00:05:51,774 --> 00:05:55,108
but actually, it's really not an object-oriented database
但实际上,这真的不是一个面向对象的数据库
134
00:05:55,177 --> 00:05:56,976
on the inside,
在里面,
135
00:05:57,045 --> 00:05:59,411
It's only an object-oriented database on the outside,
这只是一个面向对象的数据库,
136
00:05:59,480 --> 00:06:01,247
The side that you look at,
你看的一面,
137
00:06:01,315 --> 00:06:04,950
Underneath, it's actually a relational database usually,
下面,它实际上是一个关系数据库通常,
138
00:06:05,018 --> 00:06:08,987
Now Core Data is designed to have any backend of storage,
现在核心数据设计有任何后端存储,
139
00:06:09,055 --> 00:06:11,589
But it's primary implementation is on top of
但它的主要实现是最重要的
140
00:06:11,657 --> 00:06:13,957
SQL which is a relational database,
SQL是一种关系数据库,
141
00:06:14,026 --> 00:06:18,061
How many people know what SQL Database is?
有多少人知道什么是SQL数据库吗?
142
00:06:18,130 --> 00:06:19,396
Okay, almost all of you, good,
好吧,几乎所有的你,很好,
143
00:06:19,464 --> 00:06:25,268
So, if we had to do databases in our iOS apps using SQL,
所以,如果我们要做iOS应用程序使用SQL数据库,
144
00:06:25,336 --> 00:06:27,870
we'd be like no, I have to learn this whole query
我们就像不,我必须了解整个查询
145
00:06:27,939 --> 00:06:29,705
language, and how am I gonna do this?
语言,我要怎么做呢?
146
00:06:29,774 --> 00:06:32,708
Not to worry, we don't have to know any SQL to use core Data,
不要担心,我们不需要知道任何SQL使用核心数据,
147
00:06:32,776 --> 00:06:35,543
No SQL whatsoever- we're just gonna purely do this
没有任何SQL——我们要完全做到这一点
148
00:06:35,612 --> 00:06:38,280
on the object side,
在对象方面,
149
00:06:38,348 --> 00:06:39,380
So how does this work?
所以这是如何工作的呢?
150
00:06:39,449 --> 00:06:40,380
How does core Data work?
核心数据是如何工作的呢?
151
00:06:40,449 --> 00:06:43,551
Well, first we're gonna create a visual mapping
首先,我们要创建一个视觉映射
152
00:06:43,619 --> 00:06:45,985
between things in our database and
在我们数据库和之间的事情
153
00:06:46,054 --> 00:06:48,688
some objects that we're gonna be able to program with
一些对象,我们要能够计划
154
00:06:48,757 --> 00:06:51,791
in our object-oriented code that we like,
我们喜欢在我们的面向对象的代码,
155
00:06:51,860 --> 00:06:54,793
And kinda roughly, it's
有点粗略,它
156
00:06:54,862 --> 00:06:58,597
the tables in the database are kinda gonna be objects,
数据库中的表都有点要对象,
157
00:06:58,666 --> 00:07:01,833
And the columns in the tables are kind of vars,
和列在表的var,
158
00:07:01,902 --> 00:07:04,069
But we don't even really care what it's doing there,
但我们甚至不关心它在做什么,
159
00:07:04,137 --> 00:07:06,737
What we're gonna focus on is this visual map,
这是我们要关注的视觉地图,
160
00:07:06,806 --> 00:07:10,607
this visual description basically of our schema,
这种视觉描述基本的模式,
161
00:07:10,676 --> 00:07:12,509
Okay, how many people know what the word schema means?
好的,有多少人知道这个词模式意味着什么吗?
162
00:07:12,578 --> 00:07:15,812
Okay, so two-thirds of you,
好的,所以你的2/3,
163
00:07:15,881 --> 00:07:18,748
So schema is basically the description of what's
所以模式基本上是描述的
164
00:07:18,816 --> 00:07:22,218
in your database, not the contents of it but how all its
在您的数据库,而不是它的内容,但其所有
165
00:07:22,287 --> 00:07:24,687
data types are and how they relate to each other, etc,
数据类型以及它们与对方,等,
166
00:07:24,756 --> 00:07:27,923
So we're gonna do all that graphically,
所以我们要做所有的图形,
167
00:07:27,992 --> 00:07:30,325
And this is what it looks like,
这就是它的样子,
168
00:07:30,394 --> 00:07:33,428
First, if I wanna use Core Data in my app,
首先,如果我想要在我的程序中使用核心数据,
169
00:07:33,497 --> 00:07:37,498
I'm almost certainly going to wanna click this button
我几乎可以肯定会想点击这个按钮
170
00:07:37,567 --> 00:07:39,366
that says Use Core Data,
说使用核心数据,
171
00:07:39,435 --> 00:07:41,869
We've seen it every time we've created an app, and we haven't
我们已经看到它每次我们已经创建了一个应用程序,我们没有
172
00:07:41,938 --> 00:07:43,870
clicked it so far, but now we are going to click it,
点击它到目前为止,但现在我们要点击它,
173
00:07:43,939 --> 00:07:45,872
And clicking Use Core Data there,
点击使用核心数据,
174
00:07:45,940 --> 00:07:48,875
is gonna create two things for us, this visual map,
会为我们创建两个事物,这种视觉地图,
175
00:07:48,943 --> 00:07:50,943
and some code in your App Delegate,
和一些代码在应用程序委托,
176
00:07:51,012 --> 00:07:52,878
And I'm gonna talk about both of those things,
我要谈论这些事情,
177
00:07:52,946 --> 00:07:54,112
Now before I go to the next slide,
在我去下一张幻灯片之前,
178
00:07:54,181 --> 00:07:56,948
notice that the name of this app is CoreDataExample,
请注意,这个应用程序的名称是CoreDataExample,
179
00:07:57,017 --> 00:07:59,317
That's the, just the name of the app that I typed in there,
的,只是应用程序,我输入的名字,
180
00:08:00,487 --> 00:08:03,386
So when I create this app, clicking that
所以当我创建这个应用程序,点击
181
00:08:03,455 --> 00:08:06,790
Use Core Data on, you'll see that it created this file,
使用核心数据,你会发现它创建这个文件,
182
00:08:06,859 --> 00:08:10,260
CoreDataExample,xcdatamodeld,
CoreDataExample xcdatamodeld,
183
00:08:10,329 --> 00:08:12,395
So it chose the name of my app as it,
所以选择了我的程序,因为它的名字,
184
00:08:12,463 --> 00:08:16,332
And this is going to be our data model, all right?
这将是我们的数据模型,对吧?
185
00:08:16,401 --> 00:08:18,433
And so we'll, we'll talk about the AppDelegate
所以我们会,我们会讨论在AppDelegate
186
00:08:18,502 --> 00:08:21,570
code that Use Core Data also generated a little bit later,
代码也使用核心数据生成一点后,
187
00:08:21,639 --> 00:08:25,473
Right now we're gonna focus on this data model file,
现在我们要关注这个数据模型文件,
188
00:08:25,542 --> 00:08:28,977
All right, but before we even do that, what happens if we
好吧,但是在我们即使这样做,如果我们发生了什么
189
00:08:29,045 --> 00:08:32,413
have an existing app and you did not click Use Core Data?
有一个现有的应用程序和你没有点击使用核心数据?
190
00:08:32,482 --> 00:08:34,748
And now you decided, hey, I wanna add core data,
现在你决定,嘿,我想添加核心数据,
191
00:08:34,817 --> 00:08:38,318
Like maybe Smashtag Assignment 5 comes out and
比如Smashtag作业5出来
192
00:08:38,386 --> 00:08:40,953
I tell you to add some Core Data to Smashtag,
我告诉你添加一些Smashtag核心数据,
193
00:08:41,022 --> 00:08:42,789
And you're like, woh, I can't go back and
和你像,哇,我不能回去
194
00:08:42,857 --> 00:08:44,690
click Use Core Data, it's too late,
点击使用核心数据,太晚了,
195
00:08:44,759 --> 00:08:47,726
So you're gonna have to create this data model file
所以你必须创建这个数据模型文件
196
00:08:47,794 --> 00:08:48,827
using new file,
使用新文件,
197
00:08:48,896 --> 00:08:51,463
So you just go to File > New > File like this,
所以你只是去File > New >这样的文件,
198
00:08:51,532 --> 00:08:52,830
You're not gonna pick any of
你不会选择任何
199
00:08:52,899 --> 00:08:54,465
the things we've picked so far,
我们已经选择了到目前为止,
200
00:08:54,533 --> 00:08:56,600
You're gonna scroll down to the section that
你会向下滚动的部分