diff --git a/README.md b/README.md index 8c7cf67ba..d9b6ba7d9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # 戴铭的开发小册子 5.0 Swift开发的手册,是个 macOS 程序。[在线文字版](https://ming1016.github.io/2021/11/23/daiming-swift-pamphlet/) + ![](https://user-images.githubusercontent.com/251980/153746040-8379ad07-4f64-4cb2-b162-40a80fb87d6b.PNG) ## 下载 diff --git a/SwiftPamphletApp.xcodeproj/project.pbxproj b/SwiftPamphletApp.xcodeproj/project.pbxproj index cceaca4a0..0ee4b6643 100644 --- a/SwiftPamphletApp.xcodeproj/project.pbxproj +++ b/SwiftPamphletApp.xcodeproj/project.pbxproj @@ -206,8 +206,6 @@ 08AEAEDD277EA64900B969E2 /* DBDevNoti.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEDC277EA64900B969E2 /* DBDevNoti.swift */; }; 08AEAEE1277EA70500B969E2 /* DBRepoStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEE0277EA70500B969E2 /* DBRepoStore.swift */; }; 08AEAEF1277F09D000B969E2 /* IntroView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEF0277F09D000B969E2 /* IntroView.swift */; }; - 08AEAEF3277F09FA00B969E2 /* NavView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEF2277F09FA00B969E2 /* NavView.swift */; }; - 08AEAEF5277F0A1E00B969E2 /* SPSidebar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEF4277F0A1E00B969E2 /* SPSidebar.swift */; }; 08AEAEFA277F3C7400B969E2 /* css.html in Resources */ = {isa = PBXBuildFile; fileRef = 08AEAEF9277F3C7400B969E2 /* css.html */; }; 08B4C9392770B26700742084 /* CCYRSSReq.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08B4C9382770B26700742084 /* CCYRSSReq.swift */; }; 08B4C93C2774786800742084 /* archiveRepos.json in Resources */ = {isa = PBXBuildFile; fileRef = 08B4C93B2774786800742084 /* archiveRepos.json */; }; @@ -484,8 +482,6 @@ 08AEAEDC277EA64900B969E2 /* DBDevNoti.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBDevNoti.swift; sourceTree = ""; }; 08AEAEE0277EA70500B969E2 /* DBRepoStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBRepoStore.swift; sourceTree = ""; }; 08AEAEF0277F09D000B969E2 /* IntroView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntroView.swift; sourceTree = ""; }; - 08AEAEF2277F09FA00B969E2 /* NavView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavView.swift; sourceTree = ""; }; - 08AEAEF4277F0A1E00B969E2 /* SPSidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPSidebar.swift; sourceTree = ""; }; 08AEAEF9277F3C7400B969E2 /* css.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = css.html; sourceTree = ""; }; 08B4C9382770B26700742084 /* CCYRSSReq.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCYRSSReq.swift; sourceTree = ""; }; 08B4C93B2774786800742084 /* archiveRepos.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = archiveRepos.json; sourceTree = ""; }; @@ -1016,9 +1012,7 @@ 083554E227572BB60095E0EE /* AppVM.swift */, 086A5F432744EE2800FECE02 /* SwiftPamphletAppConfig.swift */, 086A5F062744E88E00FECE02 /* SwiftPamphletAppApp.swift */, - 08AEAEF4277F0A1E00B969E2 /* SPSidebar.swift */, 08AEAEF0277F09D000B969E2 /* IntroView.swift */, - 08AEAEF2277F09FA00B969E2 /* NavView.swift */, 084E1A6427B51EDB0072BBB6 /* AutoTask.swift */, ); path = App; @@ -1736,7 +1730,6 @@ 08ED801C2B9D1EEC0069B7EC /* SettingView.swift in Sources */, 08CD61FE27758B8A008C0935 /* Lexer.swift in Sources */, 086A5F422744EDCE00FECE02 /* IssueVM.swift in Sources */, - 08AEAEF3277F09FA00B969E2 /* NavView.swift in Sources */, 086A5F352744ED9600FECE02 /* IssueView.swift in Sources */, 08522BF027CF9FFA005FF059 /* PlayAnimation.swift in Sources */, 08AEAEDD277EA64900B969E2 /* DBDevNoti.swift in Sources */, @@ -1770,7 +1763,6 @@ 086A5F412744EDCE00FECE02 /* UserVM.swift in Sources */, 08A9E1A42BC2837500A73764 /* APIUserVM.swift in Sources */, 08BE633527BF54A0002BC6A8 /* PlayTextEditorView.swift in Sources */, - 08AEAEF5277F0A1E00B969E2 /* SPSidebar.swift in Sources */, 086A5F642754C14F00FECE02 /* PlayTextView.swift in Sources */, 08397E292B9F0A9100DFDD02 /* EditInfoView.swift in Sources */, 086A5F372744ED9600FECE02 /* UserView.swift in Sources */, @@ -1943,7 +1935,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 5.0; + MARKETING_VERSION = 6.0; OTHER_LDFLAGS = ( "-Xlinker", "-interposable", @@ -1986,7 +1978,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 5.0; + MARKETING_VERSION = 6.0; PRODUCT_BUNDLE_IDENTIFIER = com.starming.SwiftPamphletAppByMing; PRODUCT_NAME = "戴铭的开发小册子"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/SwiftPamphletApp/App/IntroView.swift b/SwiftPamphletApp/App/IntroView.swift index d7afc2d74..fefee31b2 100644 --- a/SwiftPamphletApp/App/IntroView.swift +++ b/SwiftPamphletApp/App/IntroView.swift @@ -6,10 +6,9 @@ // import SwiftUI -//import Inject +import MarkdownUI struct IntroView: View { -// @ObservedObject private var iO = Inject.observer var body: some View { VStack(spacing: 15) { Image("logo") @@ -21,7 +20,10 @@ struct IntroView: View { Text("一本活的开发手册") Link("GitHub 地址", destination: URL(string: "https://github.com/ming1016/SwiftPamphletApp")!) } - Text("版本5.0").font(.footnote) + if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { + Text("版本\(version)").font(.footnote) + } + Markdown(loadBundleString("1.md")) } .frame(minWidth: SPC.detailMinWidth) // .enableInjection() diff --git a/SwiftPamphletApp/App/NavView.swift b/SwiftPamphletApp/App/NavView.swift deleted file mode 100644 index 02d08a5dc..000000000 --- a/SwiftPamphletApp/App/NavView.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// NavView.swift -// SwiftPamphletApp -// -// Created by Ming Dai on 2021/12/31. -// - -import SwiftUI - -struct NavView: View { - var body: some View { - ScrollView { - MarkdownView(s: loadBundleString("1.md")) - .padding(20) - } - .frame(minWidth: 350) - } -} diff --git a/SwiftPamphletApp/App/SPSidebar.swift b/SwiftPamphletApp/App/SPSidebar.swift deleted file mode 100644 index 4eb793892..000000000 --- a/SwiftPamphletApp/App/SPSidebar.swift +++ /dev/null @@ -1,124 +0,0 @@ -// -// SPSidebar.swift -// SwiftPamphletApp -// -// Created by Ming Dai on 2021/12/31. -// - -import SwiftUI - -// MARK: - Sidebar -struct SPSidebar: View { - @Environment(AppVM.self) var appVM - var body: some View { - List { - Section("新动态") { - NavigationLink { - DataSortingListView() - } label: { - SideBarLabel(title: "资料整理", imageName: "p11") - } - } - Section("Github") { - - if SPC.gitHubAccessToken.isEmpty == false || SPC.githubAccessToken().isEmpty == false { - NavigationLink { - ExploreRepoListView(showAsGroup: false) - } label: { - SideBarLabel(title: "库动态", imageName: "p6") - .badge(appVM.expCountNotis) - - } // end NavigationLink - - NavigationLink(destination: ActiveDeveloperListView(vm: IssueVM(repoName: SPC.pamphletIssueRepoName, issueNumber: 30))) { - SideBarLabel(title: "开发者", imageName: "p5") - .badge(appVM.devsCountNotis) - } // end NavigationLink - - } // end if - - NavigationLink { - ExploreRepoListView(showAsGroup: true) - } label: { - SideBarLabel(title: "探索库", imageName: "p24") - } // end NavigationLink - - NavigationLink { - ExploreRepoListView(showAsGroup: true, isArchive: true) - } label: { - SideBarLabel(title: "库存档", imageName: "p25") - } - - } // end Section - - Section("Swift指南") { - NavigationLink(destination: IssuesListFromCustomView(vm: IssueVM(guideName:"guide-syntax"))) { - SideBarLabel(title: "语法速查", imageName: "p23") - } - - NavigationLink(destination: IssuesListFromCustomView(vm: IssueVM(guideName:"guide-features"))) { - SideBarLabel(title: "特性", imageName: "p10") - } - - NavigationLink(destination: IssuesListFromCustomView(vm: IssueVM(guideName:"guide-subject"))) { - SideBarLabel(title: "专题", imageName: "p12") - } - } - Section("库使用指南") { - NavigationLink(destination: IssuesListFromCustomView(vm: IssueVM(guideName:"lib-SwiftUI"))) { - SideBarLabel(title: "SwiftUI", imageName: "p3") - } - - NavigationLink(destination: IssuesListFromCustomView(vm: IssueVM(guideName:"lib-Combine"))) { - SideBarLabel(title: "Combine", imageName: "p19") - } - - NavigationLink(destination: IssuesListFromCustomView(vm: IssueVM(guideName:"lib-Concurrency"))) { - SideBarLabel(title: "Concurrency", imageName: "p1") - } - - } - -// Section("个人") { -// /// isExpanded 来控制是否展开 -// /// 详细查看WWDC:[WWDC 2020: Stacks, Grids, and Outlines in SwiftUI](https://developer.apple.com/videos/play/wwdc2020/10031/) -// DisclosureGroup(content: { -// Text("待建设") -// }, label: { -// Label("我的", systemImage: "person") -// }) -// } - - } - .listStyle(SidebarListStyle()) - .frame(minWidth: 160) - .toolbar { -// ToolbarItem { -// Menu { -// Text("Ops!发现这里了") -// Text("彩蛋下个版本见") -// Text("隐藏彩蛋1") -// Text("隐藏彩蛋2") -// } label: { -// Label("Label", systemImage: "slider.horizontal.3") -// } -// } - } - // end List - - // MARK: - Mine -// Spacer() -// Mine() - } -} - -struct Mine: View { - var body: some View { - HStack { - Label("我的", systemImage: "person") - Spacer() - } - .padding(20) - - } -} diff --git a/SwiftPamphletApp/App/SwiftPamphletAppApp.swift b/SwiftPamphletApp/App/SwiftPamphletAppApp.swift index 67a8aeb65..11a7d7a0d 100644 --- a/SwiftPamphletApp/App/SwiftPamphletAppApp.swift +++ b/SwiftPamphletApp/App/SwiftPamphletAppApp.swift @@ -16,11 +16,8 @@ struct SwiftPamphletAppApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { -// SwiftPamphletApp() // 老版本 - HomeView() // 新版本 -// PlayWeatherView() + HomeView() .modelContainer(for: [IOInfo.self, DeveloperModel.self], isUndoEnabled: true) - } .windowToolbarStyle(UnifiedWindowToolbarStyle(showsTitle: true)) // 用来控制是否展示标题 Settings { @@ -55,86 +52,7 @@ struct V: View { } } -struct SwiftPamphletApp: View { - - @State var appVM = AppVM() - @State var networkMonitor = NetworkMonitor() - - @State var sb = Set() - @State var alertMsg = "" - - @State private var showNetworkAlert = false // 网络监控 - - let timerForDevs = Timer.publish(every: SPC.timerForDevsSec, on: .main, in: .common).autoconnect() - let timerForExp = Timer.publish(every: SPC.timerForExpSec, on: .main, in: .common).autoconnect() - let timerForRss = Timer.publish(every: SPC.timerForRssSec, on: .main, in: .common).autoconnect() - var body: some View { - NavigationView { - SPSidebar() - .onReceive(timerForDevs, perform: { _ in - if SPC.gitHubAccessToken.isEmpty == false || SPC.githubAccessToken().isEmpty == false { - if let userName = appVM.timeForDevsEvent() { - let vm = UserVM(userName: userName) - vm.doing(.notiEvent) - } - } - }) - .onReceive(timerForExp) { _ in - if SPC.gitHubAccessToken.isEmpty == false || SPC.githubAccessToken().isEmpty == false { - appVM.timeForExpEvent() - } - } - IssuesListFromCustomView(vm: IssueVM(guideName:"guide-syntax")) - .frame(minWidth:60) - IntroView() - NavView() - - } // end NavigationView - .frame(minHeight: 650) - .navigationTitle("戴铭的开发小册子") - .navigationSubtitle(appVM.alertMsg) - .toolbar { - ToolbarItem(placement: ToolbarItemPlacement.navigation) { - Button { - appVM.toggleSidebar() - } label: { - Label("Sidebar", systemImage: "sidebar.left") - } - } - - ToolbarItemGroup(placement: ToolbarItemPlacement.automatic) { - // 博客链接用浏览器打开,还有共享菜单进行分享用 - if !appVM.webLinkStr.isEmpty { - ShareView(s: appVM.webLinkStr) - Button { - gotoWebBrowser(urlStr: appVM.webLinkStr) - } label: { - Label("Browser", systemImage: "safari") - Text("用浏览器打开") - } // end Button - } // end if - - Button { - appVM.toggleLastView() - } label: { - Label("LastView", systemImage: "sidebar.right") - } // end Button - } // end ToolbarItemGroup - } // end .toolbar - .environment(appVM) - // 网络监控 - .environment(networkMonitor) - .onChange(of: networkMonitor.hasNetworkConnection, { oldValue, newValue in - showNetworkAlert = !newValue - }) - .alert("NO INTERNET", - isPresented: $showNetworkAlert, - actions: { - Text("Close") - }) - } -} // MARK: - UnCat protocol Jsonable : Identifiable, Decodable, Hashable {} diff --git a/SwiftPamphletApp/GitHubAPI/APIVM/GitHubReq.swift b/SwiftPamphletApp/GitHubAPI/APIVM/GitHubReq.swift index 49b53d82b..fa0118fdb 100644 --- a/SwiftPamphletApp/GitHubAPI/APIVM/GitHubReq.swift +++ b/SwiftPamphletApp/GitHubAPI/APIVM/GitHubReq.swift @@ -33,9 +33,7 @@ class GitHubReq { let de = JSONDecoder() de.keyDecodingStrategy = .convertFromSnakeCase - let typeData = try de.decode(type.self, from: data) - - return typeData + return try de.decode(type.self, from: data) } } @@ -49,7 +47,7 @@ enum APIError: Error { case .server: return "api 服务出错" case .client: - return "客户端出错" + return "端侧网络出错" case .parseError: return "网络出错" } diff --git a/SwiftPamphletApp/HomeUI/HomeView.swift b/SwiftPamphletApp/HomeUI/HomeView.swift index 167b4f716..f43de8ad5 100644 --- a/SwiftPamphletApp/HomeUI/HomeView.swift +++ b/SwiftPamphletApp/HomeUI/HomeView.swift @@ -49,12 +49,7 @@ struct HomeView: View { type: .detail ) } else { - ContentUnavailableView { - Label("未选", - systemImage: "pencil.tip.crop.circle.badge.plus") - } description: { - Text("请选择或按+号添加内容") - } + IntroView() } } .environment(appVM)