-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy path11. Drag and Drop, Table View, and Collection View.srt
6428 lines (4823 loc) · 136 KB
/
11. Drag and Drop, Table View, and Collection View.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,403
本字幕由志愿者义务贡献,采用许可协议
知识共享 署名-非商业性使用-相同方式共享 3.0 美国
2
00:00:04,471 --> 00:00:07,639
Stanford University. >> Well,
>> 斯坦福大学 >> 好
3
00:00:07,708 --> 00:00:11,843
welcome to lecture number 11 of Stanford CS193P,
欢迎来到斯坦福 CS193P 的第十一节课
4
00:00:11,912 --> 00:00:16,381
this is fall of 2017 quarter. And today, we have two huge
现在是 2017 年秋季学期。今天我们有两个很重要的
5
00:00:16,450 --> 00:00:19,584
topics to talk about. The first one is drag and drop,
6
00:00:19,653 --> 00:00:22,153
which is a way of sharing information between apps,
7
00:00:22,222 --> 00:00:24,422
especially important with iOS 11.
8
00:00:24,491 --> 00:00:27,726
Because on the iPad, there's quite a great multitasking
9
00:00:27,794 --> 00:00:30,929
ability to have two apps on screen at the same time. And
10
00:00:30,997 --> 00:00:33,431
nice, nice to be able to drag and drop between them. And
11
00:00:33,500 --> 00:00:37,102
then we're gonna talk about TableView and CollectionView,
12
00:00:37,170 --> 00:00:40,439
definitely a big step up in complexity of what I've been
13
00:00:40,507 --> 00:00:44,109
teaching you so far, but I think you're ready for it. So
14
00:00:44,178 --> 00:00:47,045
drag and drop, what is drag and drop about?
15
00:00:47,114 --> 00:00:50,682
It's very simple, you literally just press and hold,
16
00:00:50,751 --> 00:00:54,452
which we call a long press on iOS, on something that could
17
00:00:54,521 --> 00:00:58,257
be dragged and start moving. And when you do, the operating
18
00:00:58,325 --> 00:01:01,660
system, iOS, is going to let you drag that thing around.
19
00:01:01,729 --> 00:01:04,496
And then you can drag it over things that might receive it
20
00:01:04,564 --> 00:01:07,332
and let go, and it drops them in there, simple as that.
21
00:01:07,401 --> 00:01:10,035
You've seen drag and drop on the desktop all the time,
22
00:01:10,104 --> 00:01:11,869
so now we have it with multitasking.
23
00:01:11,938 --> 00:01:14,973
What's really incredible about the way they did drag and drop
24
00:01:15,042 --> 00:01:17,876
is that while you're dragging and dropping, and you're
25
00:01:17,944 --> 00:01:20,745
dragging thing around, you can use your other finger and
26
00:01:20,814 --> 00:01:24,115
still completely use your UI however you want. So drag and
27
00:01:24,184 --> 00:01:27,452
drop does not interfere with the operation of your iPad at
28
00:01:27,520 --> 00:01:30,288
all. Which is quite amazing cuz you can be in the middle
29
00:01:30,357 --> 00:01:32,824
of a drag and say, well, actually I need to navigate to
30
00:01:32,893 --> 00:01:35,260
this other part of my app to drop that and it'll work. And
31
00:01:35,328 --> 00:01:37,662
it's kind of the value of having multi-touch
32
00:01:37,731 --> 00:01:40,632
multi-fingers. You can also be in the middle of a drag and
33
00:01:40,701 --> 00:01:42,801
say, hm, I wanna drag these other things too.
34
00:01:42,869 --> 00:01:45,604
And just tap on other things, it'll add it to the drag.
35
00:01:45,672 --> 00:01:48,506
So they really use the multi-fingers or multi-touch
36
00:01:48,575 --> 00:01:52,644
to great effect with drag and drop. So how do we implement
37
00:01:52,713 --> 00:01:54,780
drag and drop? What do we do in our code if we wanna
38
00:01:54,848 --> 00:01:59,117
participate in drag and drop? The real gateway to making
39
00:01:59,185 --> 00:02:02,353
this work is through these things called interactions. So
40
00:02:02,422 --> 00:02:05,190
drag and a drop is a view thing, it's a UI view thing.
41
00:02:05,259 --> 00:02:08,527
In the same way that gestures are kind of a UI view thing,
42
00:02:08,595 --> 00:02:10,228
you can sort of think of drag and
43
00:02:10,297 --> 00:02:13,898
drop as just another really powerful gesture if you want.
44
00:02:13,967 --> 00:02:16,868
But you don't enable drag and drop by adding a gesture
45
00:02:16,937 --> 00:02:20,872
recognizer, instead you do it by adding a dropInteraction or
46
00:02:20,941 --> 00:02:23,474
a dragInteraction. But it looks
47
00:02:23,543 --> 00:02:26,578
almost exactly the same as adding a gesture recognizer.
48
00:02:26,646 --> 00:02:29,747
UI view just has this method called addInteraction,
49
00:02:29,816 --> 00:02:31,315
and it takes either a drag or
50
00:02:31,384 --> 00:02:33,384
a drop interaction that you create. And
51
00:02:33,453 --> 00:02:36,221
the drag or drop interaction is created really easily.
52
00:02:36,289 --> 00:02:39,157
It just has one argument to its initializer,
53
00:02:39,226 --> 00:02:42,093
which is a delegate. And then, what's gonna happen is,
54
00:02:42,162 --> 00:02:45,697
when a drag or a drop or both, you can have a view be both,
55
00:02:45,766 --> 00:02:48,533
starts the Delegator's gonna start receiving some messages.
56
00:02:48,602 --> 00:02:50,668
And you have to respond to those messages,
57
00:02:50,737 --> 00:02:52,737
that are sent to it if you wanna participate, and
58
00:02:52,806 --> 00:02:54,906
those messages are really easy to respond to.
59
00:02:54,975 --> 00:02:55,841
So let's take a look at that,
60
00:02:55,909 --> 00:02:59,344
let's first look at being a drag person, a view that has
61
00:02:59,412 --> 00:03:03,348
something in you that you want to drag into other apps.
62
00:03:03,417 --> 00:03:06,952
If you want to register that dragInteraction on your view,
63
00:03:07,020 --> 00:03:09,955
then when the user does that long press and
64
00:03:10,024 --> 00:03:12,357
move, which looks like a drag, you know,
65
00:03:12,426 --> 00:03:15,927
for drag with drag and drop, you're gonna get this message,
66
00:03:15,996 --> 00:03:19,464
DragInteraction, itemsForBeginning. And
67
00:03:19,533 --> 00:03:22,734
this is really simple. You're just gonna return an array of
68
00:03:22,802 --> 00:03:26,471
the items you are willing to have dragged from your view.
69
00:03:26,540 --> 00:03:30,308
So what does a drag item look like? Well a drag item really
70
00:03:30,377 --> 00:03:32,744
only has one important thing, which is,
71
00:03:32,813 --> 00:03:36,113
what's called an itemProvider. Now an itemProvider is just
72
00:03:36,182 --> 00:03:39,184
something that can provide the data that's gonna be dragged.
73
00:03:39,253 --> 00:03:41,753
And you might ask, well how come the drag item just
74
00:03:41,821 --> 00:03:44,722
doesn't have the data? The thing you want to drag.
75
00:03:44,791 --> 00:03:47,425
And the reason is it might be expensive for
76
00:03:47,494 --> 00:03:50,361
you to create that data. Maybe it's an image or
77
00:03:50,430 --> 00:03:53,531
something you have to load up for some reason or
78
00:03:53,600 --> 00:03:58,002
do something else. So drag and drop is incredibly completely
79
00:03:58,071 --> 00:04:00,939
asynchronous. You start that drag and
80
00:04:01,008 --> 00:04:03,641
it's really lightweight and it's dragging around and
81
00:04:03,710 --> 00:04:06,511
almost nothing is happening as this happens. But then,
82
00:04:06,579 --> 00:04:09,381
when the drop happens, then if you're an item provider,
83
00:04:09,450 --> 00:04:12,384
you have to actually, give the data out.
84
00:04:12,452 --> 00:04:15,020
Even if that takes a certain amount of time.
85
00:04:15,089 --> 00:04:16,821
So that's why we've added itemProviders.
86
00:04:16,890 --> 00:04:19,624
Now luckily, there's a lot of built-in itemProviders.
87
00:04:19,693 --> 00:04:23,194
Classes that already exist in iOS that are itemPoviders like
88
00:04:23,263 --> 00:04:26,698
NSAttributedString. So you can drag, pick up pieces of text
89
00:04:26,766 --> 00:04:29,834
and they'll drag around with their fonts and everything.
90
00:04:29,903 --> 00:04:33,971
There's also NSString, which is text without the fonts.
91
00:04:34,040 --> 00:04:35,706
UIImage of course. You can pick up and
92
00:04:35,775 --> 00:04:39,177
drag UIImages around. NSURL, that's a really nice one.
93
00:04:39,246 --> 00:04:41,780
You go onto a web page, you pickup a URL and drop it.
94
00:04:41,848 --> 00:04:44,582
Maybe it's a reference to an article or a URL for
95
00:04:44,651 --> 00:04:46,485
an image like we're gonna have in the demo that we're gonna
96
00:04:46,553 --> 00:04:50,589
build, etc. UIColor, MapItem, a contact from the address
97
00:04:50,657 --> 00:04:53,058
book, lot of things you can pickup and move.
98
00:04:53,126 --> 00:04:56,695
These are all itemProviders. So to create a drag item you
99
00:04:56,764 --> 00:04:58,763
just create them with NSItemProvider and
100
00:04:58,832 --> 00:05:01,399
provide the object that is going to provide the data.
101
00:05:01,468 --> 00:05:04,535
Now of course you could write your own item Provider that
102
00:05:04,604 --> 00:05:07,539
provides your own kind of data, but you know, most of
103
00:05:07,608 --> 00:05:11,009
time your just gonna use these nice pre-made ones. There's
104
00:05:11,077 --> 00:05:14,579
one other thing in a dragItem, which is for local drags.
105
00:05:14,648 --> 00:05:17,916
Drag and drop can work within an app and between apps.
106
00:05:17,984 --> 00:05:20,985
It only works between apps on iPad, because you can only
107
00:05:21,054 --> 00:05:23,521
get two apps on screen at the same time in iPad.
108
00:05:23,590 --> 00:05:27,158
But on the iPhone and iPad, you can do it inside the app.
109
00:05:27,226 --> 00:05:30,128
And if you're drag and drop inside the app, then you can
110
00:05:30,196 --> 00:05:33,197
kind of short circuit all this itemProvider business and
111
00:05:33,266 --> 00:05:36,167
just use this little var, localObject in your dragItem
112
00:05:36,235 --> 00:05:39,404
and that'll just mean you're dragging this local object.
113
00:05:39,473 --> 00:05:42,574
And that local object can be anything, it's of type any, so
114
00:05:42,643 --> 00:05:45,576
you can put anything you want there and drag, use drag and
115
00:05:45,645 --> 00:05:49,047
drop to drag anything in your app from one place to another.
116
00:05:49,115 --> 00:05:50,582
So that's getting a drag started,
117
00:05:50,651 --> 00:05:52,984
you just got to provide this items for beginning array and
118
00:05:53,053 --> 00:05:57,889
that's it. If in the middle of a drag, someone uses another
119
00:05:57,957 --> 00:06:02,160
finger to pick on something else that they want to drag.
120
00:06:02,229 --> 00:06:05,096
Then you're gonna get this message itemsForAddingTo,
121
00:06:05,165 --> 00:06:09,600
this session. And all you have to do there, provide
122
00:06:09,669 --> 00:06:12,537
an array of drag items. Often that array of dragItems
123
00:06:12,605 --> 00:06:14,939
would just be one dragItem or it could be empty in
124
00:06:15,008 --> 00:06:16,975
neither items for beginning or items for
125
00:06:17,043 --> 00:06:19,243
adding two if you return an empty array here,
126
00:06:19,312 --> 00:06:22,981
it means I don't have anything to drag. Thank for asking. So
127
00:06:23,050 --> 00:06:26,184
it's really easy to just not participate if you don't want
128
00:06:26,253 --> 00:06:29,587
to. So that makes the drag start and that's it.
129
00:06:29,656 --> 00:06:32,857
That's all you have to do to be a drag source. Now,
130
00:06:32,926 --> 00:06:36,661
what about accepting a drop. So now you're on the other
131
00:06:36,729 --> 00:06:38,163
side of the drop. Someone dropped it on you.
132
00:06:38,231 --> 00:06:40,431
Well, this is kind of a multi-step process.
133
00:06:40,500 --> 00:06:42,833
The first one is you're gonna get this message sent to you.
134
00:06:42,902 --> 00:06:45,470
Again, this is if you add interaction,
135
00:06:45,539 --> 00:06:47,572
UIDropInteraction to UIView.
136
00:06:47,640 --> 00:06:50,908
You're gonna get this message when a drag starts heading
137
00:06:50,977 --> 00:06:54,845
your way, which is canHandle. Drop interaction canHandle.
138
00:06:54,914 --> 00:06:57,616
And you're gonna get this session thing and it returns
139
00:06:57,684 --> 00:07:01,653
a Bool which is whether you can handle a drag like that.
140
00:07:01,722 --> 00:07:04,422
So what is a drag like that mean? Well you have to look at
141
00:07:04,491 --> 00:07:07,625
this session that it passed you there, that UIDragSession.
142
00:07:07,694 --> 00:07:10,195
And you usually aren't gonna call one method in there which
143
00:07:10,263 --> 00:07:14,732
is canLoadObjects(ofClass. You're gonna ask that session.
144
00:07:14,801 --> 00:07:16,868
Well can you provide an NSString?
145
00:07:16,937 --> 00:07:20,905
If so, I'm in. Can you provide a UIImage? I'm in.
146
00:07:20,973 --> 00:07:24,442
Or if not, can't provide the things you're interested in,
147
00:07:24,511 --> 00:07:27,378
then you just return false from this canHandle session
148
00:07:27,447 --> 00:07:31,483
and it won't bother you anymore during this drag. So
149
00:07:31,551 --> 00:07:34,686
that's to get it started. Now if you were to say yes, I
150
00:07:34,754 --> 00:07:38,289
can load objects of that type. Then you're going to start
151
00:07:38,358 --> 00:07:42,026
getting this sessionDidUpdate message sent to you. Again,
152
00:07:42,095 --> 00:07:43,829
this is gonna pass that session to you again.
153
00:07:43,897 --> 00:07:45,597
And the session might have changed a little,
154
00:07:45,665 --> 00:07:47,465
cuz maybe the finger has moved a little bit and so
155
00:07:47,533 --> 00:07:49,434
maybe that changes your decision about whether you
156
00:07:49,502 --> 00:07:52,036
want to accept this drop. But what you return from
157
00:07:52,105 --> 00:07:55,907
sessionDidUpdate is a UIDropProposal.
158
00:07:55,976 --> 00:07:59,477
Now this is your proposal as drop receiver. For
159
00:07:59,546 --> 00:08:01,612
what you're willing to do with this Drop, and there's really
160
00:08:01,681 --> 00:08:04,615
only three things you can do. You can have a Drop Proposal
161
00:08:04,684 --> 00:08:08,853
which is cancel, which is to say, I propose cancelling this
162
00:08:08,922 --> 00:08:10,921
Drop if you want to try and Drop it right where you
163
00:08:10,990 --> 00:08:15,059
are now because I don't accept it there. And the Drag,
164
00:08:15,128 --> 00:08:17,495
we'll have a little icon that appears on it, which is like,
165
00:08:17,564 --> 00:08:19,464
you know, a red circle with a line through it, saying,
166
00:08:19,533 --> 00:08:23,000
no, you can't drop here. Then there's Copy and Move.
167
00:08:23,069 --> 00:08:26,170
Copy and move is a proposal that says, yes, I propose,
168
00:08:26,239 --> 00:08:30,508
I will receive this drop and I will either copy the item or
169
00:08:30,576 --> 00:08:34,412
move it. Now, copy is most often which you're going to do
170
00:08:34,481 --> 00:08:36,580
here. Move would only make sense for
171
00:08:36,649 --> 00:08:39,784
a drag within your app. Because you're gonna be moving
172
00:08:39,853 --> 00:08:42,487
it from wherever it was, it won't be there anymore and
173
00:08:42,556 --> 00:08:43,688
now it's gonna be at the new place,
174
00:08:43,757 --> 00:08:45,322
that can only happen within your own app.
175
00:08:45,391 --> 00:08:48,059
So move is only inside your own app if you're actually
176
00:08:48,127 --> 00:08:50,995
moving the thing, rather than, copying and making a copy
177
00:08:51,064 --> 00:08:52,530
of it. If someone's dragging from outside,
178
00:08:52,598 --> 00:08:55,266
you'll always gonna be copying it. So that's it, you just
179
00:08:55,335 --> 00:08:58,803
have to say, cancel, move, or copy each time you are asked
180
00:08:58,871 --> 00:09:01,873
about this. By the way, you can look at the session and
181
00:09:01,942 --> 00:09:04,942
find out where the finger is in your view,
182
00:09:05,011 --> 00:09:07,412
by asking the session the location in the view.
183
00:09:07,481 --> 00:09:09,580
So some places in your view maybe looks up to drop,
184
00:09:09,649 --> 00:09:12,350
in some place not, all right.
185
00:09:12,418 --> 00:09:15,686
So that's super simple, and so this proposal is kind of
186
00:09:15,755 --> 00:09:18,789
a contract to accept the drop, if it were to be dropped at
187
00:09:18,858 --> 00:09:22,794
this location. And so if you do accept it, then,
188
00:09:22,862 --> 00:09:26,264
like if you don't say, dot cancel there in your proposal,
189
00:09:26,332 --> 00:09:29,734
then you'll get performDrop when the finger Is released,
190
00:09:29,803 --> 00:09:32,370
and the drop happens. Now, perform drop,
191
00:09:32,439 --> 00:09:34,772
you're gonna get that session back again. Here,
192
00:09:34,841 --> 00:09:37,041
you're almost always only gonna call one method,
193
00:09:37,110 --> 00:09:41,546
which is loadObjects ofClass.
194
00:09:41,615 --> 00:09:43,848
So we saw all ready the can load object class.
195
00:09:43,917 --> 00:09:45,850
Now, we have the actual load objects of class.
196
00:09:45,919 --> 00:09:47,552
Now this is an awesome little method.
197
00:09:47,620 --> 00:09:50,688
This is one of the ways they made drop, drag and drop, so
198
00:09:50,757 --> 00:09:54,159
simple, the implement without, with all that asynchrony, but
199
00:09:54,227 --> 00:09:56,827
without a lot of difficulty in your app, which is,
200
00:09:56,896 --> 00:10:00,164
you just call load objects of class. You specify
201
00:10:00,233 --> 00:10:02,399
the class you're willing to receive from the drop, so
202
00:10:02,468 --> 00:10:04,335
like attributed string or a color, or
203
00:10:04,404 --> 00:10:07,572
a URL or image, whatever. Presumably, the things you
204
00:10:07,641 --> 00:10:11,209
said you would accept earlier on, and it will go and
205
00:10:11,277 --> 00:10:14,378
get that data asynchronously on another thread. And
206
00:10:14,447 --> 00:10:16,681
when it gets all from the drag source,
207
00:10:16,749 --> 00:10:19,751
it will call the closure you provide with the first
208
00:10:19,819 --> 00:10:23,754
armament being an array of those things. So in this case,
209
00:10:23,823 --> 00:10:27,458
I'm saying, load objects of class in a distributed string,
210
00:10:27,527 --> 00:10:30,628
so it's gonna call that closure with the The Strings
211
00:10:30,697 --> 00:10:34,165
to being an array of and as attribute to string. Now, it's
212
00:10:34,234 --> 00:10:37,602
actually an array of something that implements the provider
213
00:10:37,670 --> 00:10:40,572
protocol, so you're gonna have to cast it with AS.
214
00:10:40,640 --> 00:10:43,141
But this is essentially array of those MS attributes and
215
00:10:43,209 --> 00:10:44,375
strengths. Similarly,
216
00:10:44,444 --> 00:10:47,044
you could do UIImage.self and all of that. By the way that
217
00:10:47,113 --> 00:10:49,180
NSAttributeString.self that's the way
218
00:10:49,249 --> 00:10:52,316
you specify the class in it's attributed string,
219
00:10:52,385 --> 00:10:54,319
if you wanna pass it as an argument to the function.
220
00:10:54,387 --> 00:10:57,722
We haven't seen that before but that's all you do.
221
00:10:57,791 --> 00:11:01,825
And, this closure is sent to you and implemented
222
00:11:01,894 --> 00:11:04,862
on the main queue, so you can feel free to do IU stuff here.
223
00:11:04,931 --> 00:11:07,531
You don't have to dispatch the main queue if you don't want
224
00:11:07,600 --> 00:11:10,534
to, and so it's really, really super convenient,
225
00:11:10,603 --> 00:11:12,570
to do whatever you want. And you know,
226
00:11:12,639 --> 00:11:15,106
you accept this drop, and it might take a little while for
227
00:11:15,175 --> 00:11:16,975
this information to appear, but when it does,
228
00:11:17,043 --> 00:11:20,344
you just have the code right here automatically executed.
229
00:11:20,413 --> 00:11:22,347
And you can do load objects of class,
230
00:11:22,415 --> 00:11:24,582
multiple different classes in the same drop.
231
00:11:24,651 --> 00:11:26,984
We're going to do that in the demo for example.
232
00:11:27,053 --> 00:11:29,354
We're only going to accept drags that are images, but
233
00:11:29,422 --> 00:11:32,022
that also have a URL for the image, so we're looking for
234
00:11:32,091 --> 00:11:35,059
two pieces of data in the same drag, a URL and an image. And
235
00:11:35,128 --> 00:11:39,196
we will be doing loadObjects of class both of URL and
236
00:11:39,265 --> 00:11:42,700
of the UI image, perfectly legal. They'll,
237
00:11:42,769 --> 00:11:44,168
they'll both be happening asynchronously,
238
00:11:44,237 --> 00:11:45,770
you don't know which one's gonna finish first.
239
00:11:45,838 --> 00:11:47,238
But you've gotta write your code so
240
00:11:47,307 --> 00:11:49,940
it doesn't matter. But that's all you need to do,
241
00:11:50,009 --> 00:11:52,476
and that's all you usually do in performDrop, or
242
00:11:52,545 --> 00:11:54,145
you're not really gonna do much else,
243
00:11:54,214 --> 00:11:58,983
it's just get that data to start coming your way. So
244
00:11:59,052 --> 00:12:02,921
I did drag and drop, super duper simple to implement.
245
00:12:02,989 --> 00:12:06,290
So we're gonna do a little demo of it, so you can see it
246
00:12:06,359 --> 00:12:09,861
in action, and I'm going to do this on the actual iPad and
247
00:12:09,929 --> 00:12:13,097
I think we figured a way to get this on the screen that
248
00:12:13,166 --> 00:12:15,199
will make everybody happy here.
249
00:12:15,268 --> 00:12:17,468
So the way I'm gonna do this,