Skip to content

Commit 1b1db4a

Browse files
committed
fix warning and error in xcode 11 beta 7 (11M392r)
1 parent fdb79b9 commit 1b1db4a

22 files changed

+275
-119
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
41FE99E722AAD08A008135A0 /* NavigationButtonPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41FE99E622AAD08A008135A0 /* NavigationButtonPage.swift */; };
4747
41FE99E922AAD7B0008135A0 /* EditButtonPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41FE99E822AAD7B0008135A0 /* EditButtonPage.swift */; };
4848
41FE99F022AADF9F008135A0 /* DatePickerPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41FE99EF22AADF9F008135A0 /* DatePickerPage.swift */; };
49+
D74985BC231634DA00C4D46D /* Window+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74985BB231634DA00C4D46D /* Window+Ext.swift */; };
4950
/* End PBXBuildFile section */
5051

5152
/* Begin PBXFileReference section */
@@ -90,6 +91,7 @@
9091
41FE99E622AAD08A008135A0 /* NavigationButtonPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationButtonPage.swift; sourceTree = "<group>"; };
9192
41FE99E822AAD7B0008135A0 /* EditButtonPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditButtonPage.swift; sourceTree = "<group>"; };
9293
41FE99EF22AADF9F008135A0 /* DatePickerPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerPage.swift; sourceTree = "<group>"; };
94+
D74985BB231634DA00C4D46D /* Window+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Window+Ext.swift"; sourceTree = "<group>"; };
9395
/* End PBXFileReference section */
9496

9597
/* Begin PBXFrameworksBuildPhase section */
@@ -117,6 +119,7 @@
117119
children = (
118120
4132A46222AD709300A8DBBE /* Color+Ext.swift */,
119121
4132A46522AD70D400A8DBBE /* View+Ext.swift */,
122+
D74985BB231634DA00C4D46D /* Window+Ext.swift */,
120123
);
121124
path = Extension;
122125
sourceTree = "<group>";
@@ -347,6 +350,7 @@
347350
41977FF522ACA74600FD47FE /* WebImagePage.swift in Sources */,
348351
4196ABE722AA268A008B8FD2 /* TextFieldPage.swift in Sources */,
349352
4161B32722AB68F600CD5A1B /* HStackPage.swift in Sources */,
353+
D74985BC231634DA00C4D46D /* Window+Ext.swift in Sources */,
350354
4164489D22AA6D6500A93AF2 /* ImagePage.swift in Sources */,
351355
4161B32922AB695A00CD5A1B /* VStackPage.swift in Sources */,
352356
415F044B22AB9A96003E59FC /* AlertPage.swift in Sources */,

Example/Example/ContentView.swift

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,123 +14,128 @@ struct ContentView : View {
1414
NavigationView {
1515
List {
1616
Section(header: Text("特殊视图")) {
17-
NavigationButton(destination: WebViewPage()) {
18-
PageRow(title: "WebView",subTitle: "用于展示一个打开的网页")
17+
NavigationLink(destination: WebViewPage()) {
18+
PageRow(title: "WebView", subTitle: "用于展示一个打开的网页")
1919
}
20-
NavigationButton(destination: ControllerPage<UIKitController>()) {
21-
PageRow(title: "UIViewController",subTitle: "打开 UIViewController")
20+
NavigationLink(destination: ControllerPage<UIKitController>()) {
21+
PageRow(title: "UIViewController", subTitle: "打开 UIViewController")
2222
}
2323
}
2424
Section(header: Text("基础控件")) {
25-
NavigationButton(destination: TextPage()) {
25+
NavigationLink(destination: TextPage()) {
2626
PageRow(title: "Text",subTitle: "显示一行或多行只读文本")
2727
}
28-
NavigationButton(destination: TextFieldPage()) {
28+
NavigationLink(destination: TextFieldPage()) {
2929
PageRow(title: "TextField", subTitle: "显示可编辑文本界面的输入控件")
3030
}
31-
NavigationButton(destination: TextFieldPage()) {
31+
NavigationLink(destination: TextFieldPage()) {
3232
PageRow(title: "SecureField", subTitle: "安全输入私密文本的输入控件")
3333
}
34-
NavigationButton(destination: ImagePage()) {
34+
NavigationLink(destination: ImagePage()) {
3535
PageRow(title: "Image",subTitle: "用以展示本地图片")
3636
}
37-
NavigationButton(destination: WebImagePage()) {
37+
NavigationLink(destination: WebImagePage()) {
3838
PageRow(title: "WebImage",subTitle: "下载网络图片并展示")
3939
}
4040
}
4141
Section(header: Text("按钮")) {
42-
NavigationButton(destination: ButtonPage()) {
42+
NavigationLink(destination: ButtonPage()) {
4343
PageRow(title: "Button",subTitle: "触发时执行操作的按钮")
4444
}
45-
NavigationButton(destination: NavigationButtonPage()) {
45+
NavigationLink(destination: NavigationButtonPage()) {
4646
PageRow(title: "NavigationButton",subTitle: "按下时触发导航跳转的按钮")
4747
}
48-
PresentationButton(PageRow(title: "PresentationButton", subTitle: "触发时显示内容的按钮控件"),
49-
destination: Text("I'm Text")) {
50-
print("Present 🦄")
48+
NavigationLink(destination: Text("I'm Text")) {
49+
PageRow(title: "PresentationButton",subTitle: "触发时显示内容的按钮控件")
5150
}
52-
NavigationButton(destination: EditButtonPage()) {
51+
// NavigationLink(PageRow(title: "PresentationButton", subTitle: "触发时显示内容的按钮控件"),
52+
// destination: Text("I'm Text")) {
53+
// print("Present 🦄")
54+
// }
55+
NavigationLink(destination: EditButtonPage()) {
5356
PageRow(title: "EditButton",subTitle: "用于切换当前编辑模式的按钮")
5457
}
5558
}
5659

5760
Section(header: Text("选择器")) {
58-
NavigationButton(destination: PickerPage()) {
61+
NavigationLink(destination: PickerPage()) {
5962
PageRow(title: "Picker",subTitle: "可自定义数据源的 Picker 选择器")
6063
}
61-
NavigationButton(destination: DatePickerPage()) {
64+
NavigationLink(destination: DatePickerPage()) {
6265
PageRow(title: "DatePicker",subTitle: "日期展示与选择")
6366
}
64-
NavigationButton(destination: TogglePage()) {
67+
NavigationLink(destination: TogglePage()) {
6568
PageRow(title: "Toggle",subTitle: "开关状态切换")
6669
}
67-
NavigationButton(destination: SliderPage()) {
70+
NavigationLink(destination: SliderPage()) {
6871
PageRow(title: "Slider",subTitle: "用以设置指定范围内的值")
6972
}
70-
NavigationButton(destination: StepperPage()) {
73+
NavigationLink(destination: StepperPage()) {
7174
PageRow(title: "Stepper",subTitle: "用以增加或减少数值")
7275
}
73-
NavigationButton(destination: SegmentedControlPage()) {
74-
PageRow(title: "SegmentedControl", subTitle: "用以从一组选项中进行选择")
75-
}
76+
// deprecated
77+
// NavigationLink(destination: SegmentedControlPage()) {
78+
// PageRow(title: "SegmentedControl", subTitle: "用以从一组选项中进行选择")
79+
// }
7680
}
7781

7882
Section(header: Text("布局")) {
79-
NavigationButton(destination: HStackPage()) {
83+
NavigationLink(destination: HStackPage()) {
8084
PageRow(title: "HStack",subTitle: "将子视图排列在水平线上的视图")
8185
}
82-
NavigationButton(destination: VStackPage()) {
86+
NavigationLink(destination: VStackPage()) {
8387
PageRow(title: "VStack",subTitle: "将子视图排列在垂直线上的视图")
8488
}
85-
NavigationButton(destination: ZStackPage()) {
89+
NavigationLink(destination: ZStackPage()) {
8690
PageRow(title: "ZStack",subTitle: "覆盖子视图,在两轴上对齐")
8791
}
88-
NavigationButton(destination: ListPage()) {
92+
NavigationLink(destination: ListPage()) {
8993
PageRow(title: "List",subTitle: "列表容器,用以显示一列数据")
9094
}
91-
NavigationButton(destination: ScrollViewPage()) {
95+
NavigationLink(destination: ScrollViewPage()) {
9296
PageRow(title: "ScrollView",subTitle: "滚动视图")
9397
}
94-
NavigationButton(destination: ForEachPage()) {
98+
NavigationLink(destination: ForEachPage()) {
9599
PageRow(title: "ForEach",subTitle: "用于根据已有数据的集合展示视图")
96100
}
97-
NavigationButton(destination: GroupPage()) {
101+
NavigationLink(destination: GroupPage()) {
98102
PageRow(title: "Group",subTitle: "用于集合多个视图,对 Group 设置的属性,将作用于每个子视图")
99103
}.frame(height: 80)
100-
NavigationButton(destination: SectionPage()) {
104+
NavigationLink(destination: SectionPage()) {
101105
PageRow(title: "Section",subTitle: "用于创建带头/尾部的视图内容,一般结合 `List` 组件使用")
102106
}.frame(height: 80)
103107
}
104108
Section(header: Text("导航视图")) {
105-
NavigationButton(destination: NavigationViewPage()) {
109+
NavigationLink(destination: NavigationViewPage()) {
106110
PageRow(title: "NavigationView",subTitle: "用于创建包含顶部导航栏的视图容器")
107111
}
108-
NavigationButton(destination: TabBarPage()) {
112+
NavigationLink(destination: TabBarPage()) {
109113
PageRow(title: "TabBar",subTitle: "用于创建包含底部 TabBar 的视图容器")
110114
}
111115
}
112116
Section(header: Text("Alert 弹框视图")) {
113-
NavigationButton(destination: AlertPage()) {
117+
NavigationLink(destination: AlertPage()) {
114118
PageRow(title: "Alert",subTitle: "展示一个弹框提醒")
115119
}
116-
NavigationButton(destination: ActionSheetPage()) {
120+
NavigationLink(destination: ActionSheetPage()) {
117121
PageRow(title: "ActionSheet",subTitle: "弹出一个选择框")
118122
}
119-
NavigationButton(destination: ModalPage()) {
123+
NavigationLink(destination: ModalPage()) {
120124
PageRow(title: "Modal",subTitle: "Modal 弹出一个视图")
121125
}
122-
NavigationButton(destination: PopoverPage()) {
126+
NavigationLink(destination: PopoverPage()) {
123127
PageRow(title: "Popover",subTitle: "Pop 弹出一个视图")
124128
}
125129
}
126130
}
127-
.listStyle(.grouped)
131+
.listStyle(GroupedListStyle())
128132
.navigationBarTitle(Text("Example"), displayMode: .large)
129133
.navigationBarItems(trailing: Button(action: {
130134
print("Tap")
131135
}, label: {
132-
Text("Right").color(.orange)
136+
Text("Right").foregroundColor(.orange)
133137
}))
138+
134139
}
135140
}
136141

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Window+Ext.swift
3+
// Example
4+
//
5+
// Created by spectatorNan on 2019/8/28.
6+
// Copyright © 2019 Spectator. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
struct MainApp {
12+
13+
14+
/// keyWindow
15+
// 'keyWindow' was deprecated in iOS 13.0: Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes
16+
// https://stackoverflow.com/questions/57134259/how-to-resolve-keywindow-was-deprecated-in-ios-13-0
17+
public static var keyWindow: UIWindow? {
18+
return UIApplication.shared.connectedScenes
19+
.filter({$0.activationState == .foregroundActive})
20+
.map({$0 as? UIWindowScene})
21+
.compactMap({$0})
22+
.first?.windows
23+
.filter({$0.isKeyWindow}).first ?? nil
24+
}
25+
}

Example/Example/Page/Alert/ActionSheetPage.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,44 @@ struct ActionSheetPage : View {
2020
.bold()
2121
.font(.system(.largeTitle,
2222
design: .rounded))
23-
}.presentation(sheet)
23+
}//.sheet(isPresented: $showSheet, onDismiss: nil, content: <#T##() -> View#>)
24+
//.presentation(sheet)
25+
.actionSheet(isPresented: $showSheet, content: {sheet})
2426
}
27+
28+
// NavigationView {
29+
//
30+
// Button(action: {
31+
// self.showSheet = true
32+
// }) {
33+
// Text("ActionSheet")
34+
// .bold()
35+
// .font(.system(.largeTitle,
36+
// design: .rounded))
37+
// }
38+
// }.sheet(isPresented: $showSheet, content: sheet)
39+
40+
// ActionSheet.Button.default(<#T##label: Text##Text#>, action: <#T##(() -> Void)?##(() -> Void)?##() -> Void#>)
2541
}
2642

27-
private var sheet: ActionSheet? {
43+
private var sheet: ActionSheet {
2844

2945
let action = ActionSheet(title: Text("Title"),
3046
message: Text("Message"),
3147
buttons:
32-
[.default(Text("Default"), onTrigger: {
48+
[.default(Text("Default"), action: {
3349
print("Default")
3450
self.showSheet = false
35-
}),.destructive(Text("destructive"), onTrigger: {
51+
}),.destructive(Text("destructive"), action: {
3652
print("destructive")
3753
self.showSheet = false
3854
}),.cancel({
3955
print("Cancel")
4056
self.showSheet = false
4157
})])
4258

43-
return self.showSheet ? action:nil
59+
// return self.showSheet ? action:nil
60+
return action
4461
}
4562
}
4663

Example/Example/Page/Alert/AlertPage.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ struct AlertPage : View {
2020
Text("Click")
2121
.font(.system(size: 40,
2222
design: .rounded))
23-
}.presentation($showAlert, alert: {
24-
Alert(title: Text("确定要支付这100000000美元吗?"),
25-
message: Text("请谨慎操作\n一旦确认,钱款将立即转入对方账户"),
26-
primaryButton: .destructive(Text("确认")) { print("转出中...") },
27-
secondaryButton: .cancel())
28-
}).navigationBarTitle(Text("Alert"))
23+
}
24+
.alert(isPresented: $showAlert, content: {
25+
Alert(title: Text("确定要支付这100000000美元吗?"),
26+
message: Text("请谨慎操作\n一旦确认,钱款将立即转入对方账户"),
27+
primaryButton: .destructive(Text("确认")) { print("转出中...") },
28+
secondaryButton: .cancel())
29+
}).navigationBarTitle(Text("Alert"))
30+
2931
}
3032
}
3133

Example/Example/Page/Alert/ModalPage.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ struct ModalPage : View {
1212

1313
@State var showModal = false
1414

15-
var modal: Modal {
16-
return Modal(PickerPage(),onDismiss: {
17-
print("View Dismiss !")
18-
self.showModal = false
19-
})
20-
}
15+
// var modal: Modal {
16+
// return Modal(PickerPage(),onDismiss: {
17+
// print("View Dismiss !")
18+
// self.showModal = false
19+
// })
20+
// }
21+
22+
2123

2224
var body: some View {
2325
VStack {
@@ -28,7 +30,8 @@ struct ModalPage : View {
2830
.bold()
2931
.font(.system(.largeTitle,
3032
design: .serif))
31-
}.presentation(showModal ? modal:nil)
33+
}//.presentation(showModal ? modal:nil)
34+
// .sheet(isPresented: $showModal, content: PickerPage())
3235
}
3336
}
3437
}

Example/Example/Page/Alert/PopoverPage.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ struct PopoverPage : View {
1919
print(self.showPop)
2020
}) {
2121
Text("Popover").bold().font(.system(.largeTitle, design: .monospaced))
22-
}.presentation(popView)
22+
}//.presentation(popView)
23+
.popover(isPresented: $showPop, content: {
24+
ImagePage()
25+
})
2326
}
2427
}
25-
26-
private var popView: Popover? {
28+
/*
29+
private var popView: PopImagePageover? {
2730

2831
// 以下 Dismiss 回调,按照官方文档说明是: Action which informs the caller when the popover has been dismissed.
2932
// 但实际上在pop消失后,下面 dismiss 回调始终无法触发,导致无法再次show,也许是个bug。
@@ -33,6 +36,7 @@ struct PopoverPage : View {
3336
}
3437
return self.showPop ? pop:nil
3538
}
39+
*/
3640
}
3741

3842
#if DEBUG

Example/Example/Page/Button/EditButtonPage.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import Combine
1111

1212
struct EditButtonPage : View {
1313

14-
@ObjectBinding private var source = dataSource()
14+
@ObservedObject private var source = dataSource()
1515

1616
var body: some View {
1717
List {
18-
ForEach(source.items) { idx in
18+
19+
ForEach(source.items, id: \.self) { idx in
1920
PageRow(title: "\(idx)")
2021
}
2122
.onDelete(perform: deletePlace)
@@ -26,7 +27,7 @@ struct EditButtonPage : View {
2627
}
2728

2829
func deletePlace(at offset: IndexSet) {
29-
if let last = offset.last?.id {
30+
if let last = offset.last {
3031
source.items.remove(at: last)
3132
print(source.items.count)
3233
}
@@ -35,10 +36,11 @@ struct EditButtonPage : View {
3536
func movePlace(from source: IndexSet, to destination: Int) {
3637
print(source,destination)
3738
}
39+
40+
3841
}
3942

40-
41-
class dataSource: BindableObject {
43+
class dataSource: ObservableObject {
4244

4345
public var didChange = PassthroughSubject<Void, Never>()
4446

0 commit comments

Comments
 (0)