File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change 41
41
42
42
官方教程:
43
43
44
- ```
45
- ...
44
+ ``` Swift
45
+ .
46
+ .
47
+ .
46
48
struct MapView : UIViewRepresentable {
47
49
func makeUIView (context : Context) -> MKMapView {
48
50
MKMapView (frame : .zero )
49
51
}
50
52
}
51
- ...
53
+ .
54
+ .
55
+ .
52
56
```
53
57
54
58
这里的 ` UIViewRepresentable ` 是一个协议,它的声明中包含一个 ` associatedtype ` :
55
59
56
- ```
60
+ ``` Swift
57
61
/// The type of `UIView` to be presented.
58
62
associatedtype UIViewType : UIView
59
63
```
60
64
61
65
在开发中,给此 ` associatedtype ` 赋值后 Xcode 对方法的签名补全会有变化,最终写作:
62
66
63
- ```
64
- ...
67
+ ``` Swift
68
+ .
69
+ .
70
+ .
65
71
struct MapView : UIViewRepresentable {
66
72
67
73
typealias UIViewType = MKMapView
@@ -70,7 +76,9 @@ struct MapView : UIViewRepresentable {
70
76
return MKMapView (frame : .zero )
71
77
}
72
78
}
73
- ...
79
+ .
80
+ .
81
+ .
74
82
```
75
83
76
84
如此修改不再一一列举,只需记得** 此类修改不会改变原教程的构建结果** 即可,不必过于纠结。
You can’t perform that action at this time.
0 commit comments