From 49c626dd8e1504ef9de436b1232008a41dc02b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E9=93=AD?= Date: Wed, 13 Nov 2024 09:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=BB=E5=8A=A1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftPamphletApp.xcodeproj/project.pbxproj | 12 +++++ .../Guide/View/GuideListView.swift | 5 +- SwiftPamphletApp/HomeUI/HomeView.swift | 1 - SwiftPamphletApp/HomeUI/HomeiOSView.swift | 1 + .../Performance/TaskManager.swift | 53 ++++++------------- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/SwiftPamphletApp.xcodeproj/project.pbxproj b/SwiftPamphletApp.xcodeproj/project.pbxproj index 531c225c..153f550b 100644 --- a/SwiftPamphletApp.xcodeproj/project.pbxproj +++ b/SwiftPamphletApp.xcodeproj/project.pbxproj @@ -493,6 +493,9 @@ 3AEC7F592CE38749005D510D /* OC项目启动时间(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 3AEC7F572CE38749005D510D /* OC项目启动时间(ap).md */; }; 3AEC7F5B2CE3876D005D510D /* Swift项目启动时间(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 3AEC7F5A2CE3876D005D510D /* Swift项目启动时间(ap).md */; }; 3AEC7F5D2CE39250005D510D /* 可合并库(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 3AEC7F5C2CE39250005D510D /* 可合并库(ap).md */; }; + 3AEC7F5F2CE39444005D510D /* 启动优化-线程任务管理(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 3AEC7F5E2CE39444005D510D /* 启动优化-线程任务管理(ap).md */; }; + 3AEC7F612CE398BD005D510D /* 启动优化-一些技巧(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 3AEC7F602CE398BD005D510D /* 启动优化-一些技巧(ap).md */; }; + 3AEC7F672CE39DC6005D510D /* Background Fetch(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 3AEC7F662CE39DC6005D510D /* Background Fetch(ap).md */; }; 3AF2A2DF2BE22A8C00F3BE1B /* UnCategoryInfoListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF2A2DE2BE22A8C00F3BE1B /* UnCategoryInfoListView.swift */; }; 3AF2A2E12BE22B5800F3BE1B /* UnCategoryInfosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF2A2E02BE22B5800F3BE1B /* UnCategoryInfosView.swift */; }; 3AF2A2E32BE2317300F3BE1B /* StarInfoListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF2A2E22BE2317300F3BE1B /* StarInfoListView.swift */; }; @@ -977,6 +980,9 @@ 3AEC7F572CE38749005D510D /* OC项目启动时间(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "OC项目启动时间(ap).md"; sourceTree = ""; }; 3AEC7F5A2CE3876D005D510D /* Swift项目启动时间(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Swift项目启动时间(ap).md"; sourceTree = ""; }; 3AEC7F5C2CE39250005D510D /* 可合并库(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "可合并库(ap).md"; sourceTree = ""; }; + 3AEC7F5E2CE39444005D510D /* 启动优化-线程任务管理(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "启动优化-线程任务管理(ap).md"; sourceTree = ""; }; + 3AEC7F602CE398BD005D510D /* 启动优化-一些技巧(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "启动优化-一些技巧(ap).md"; sourceTree = ""; }; + 3AEC7F662CE39DC6005D510D /* Background Fetch(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Background Fetch(ap).md"; sourceTree = ""; }; 3AF2A2DE2BE22A8C00F3BE1B /* UnCategoryInfoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnCategoryInfoListView.swift; sourceTree = ""; }; 3AF2A2E02BE22B5800F3BE1B /* UnCategoryInfosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnCategoryInfosView.swift; sourceTree = ""; }; 3AF2A2E22BE2317300F3BE1B /* StarInfoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarInfoListView.swift; sourceTree = ""; }; @@ -1315,6 +1321,8 @@ 088F2C2A2C8843E000DCA64F /* 启动优化-工具(ap).md */, 3AEC7F4A2CE37028005D510D /* 动态库与静态库(ap).md */, 3AEC7F5C2CE39250005D510D /* 可合并库(ap).md */, + 3AEC7F5E2CE39444005D510D /* 启动优化-线程任务管理(ap).md */, + 3AEC7F602CE398BD005D510D /* 启动优化-一些技巧(ap).md */, 3AEC7F4C2CE373C5005D510D /* 启动优化-测试(ap).md */, ); path = "启动优化"; @@ -1788,6 +1796,7 @@ 3A30EFD52CDA818B0029CB2F /* WeatherKit(ap).md */, 08BDD4472C6B007A00914412 /* Swift-DocC(ap).md */, 088F2C2E2C8E827300DCA64F /* Share Extension(ap).md */, + 3AEC7F662CE39DC6005D510D /* Background Fetch(ap).md */, ); path = "系统能力"; sourceTree = ""; @@ -2545,6 +2554,7 @@ 08BDD5412C6B007A00914412 /* 小组件-参考资料(ap).md in Resources */, 3AEC7F5D2CE39250005D510D /* 可合并库(ap).md in Resources */, 08BDD5092C6B007A00914412 /* Combine Timer(ap).md in Resources */, + 3AEC7F672CE39DC6005D510D /* Background Fetch(ap).md in Resources */, 083266752C96C00F00E27CC5 /* visionOS-空间设计(ap).md in Resources */, 08448FAD279EC2E900B61353 /* 泛型和协议(ap).md in Resources */, 08BDD51A2C6B007A00914412 /* Actors(ap).md in Resources */, @@ -2690,6 +2700,7 @@ 083266732C96BF0500E27CC5 /* visionOS-介绍(ap).md in Resources */, 0851E5592C86BB7600D9463A /* 测试-代码覆盖率(ap).md in Resources */, 08BDD5812C6B007A00914412 /* ContentUnavailableView(ap).md in Resources */, + 3AEC7F612CE398BD005D510D /* 启动优化-一些技巧(ap).md in Resources */, 087A7ADD2C803AD500321F85 /* 包体积-系统优化(ap).md in Resources */, 08BDD5362C6B007A00914412 /* 文件(ap).md in Resources */, 08448FA0279EBAD900B61353 /* 访问控制(ap).md in Resources */, @@ -2775,6 +2786,7 @@ 088F2C3A2C93296200DCA64F /* 笔记记录方法(ap).md in Resources */, 088F2C3E2C9329E400DCA64F /* PARA记录法(ap).md in Resources */, 3AEC7F5B2CE3876D005D510D /* Swift项目启动时间(ap).md in Resources */, + 3AEC7F5F2CE39444005D510D /* 启动优化-线程任务管理(ap).md in Resources */, 08BDD57A2C6B007A00914412 /* 自定义导航栏(ap).md in Resources */, 08BDD5B92C6B007A00914412 /* List(ap).md in Resources */, 08BDD56B2C6B007A00914412 /* Toggle(ap).md in Resources */, diff --git a/SwiftPamphletApp/Guide/View/GuideListView.swift b/SwiftPamphletApp/Guide/View/GuideListView.swift index 292c375a..645e3af9 100644 --- a/SwiftPamphletApp/Guide/View/GuideListView.swift +++ b/SwiftPamphletApp/Guide/View/GuideListView.swift @@ -483,7 +483,8 @@ final class GuideListModel { L(t: "WeatherKit", icon: "app"), L(t: "Swift-DocC", icon: "doc.append"), L(t: "AppIcon", icon: "app"), - L(t: "Share Extension", icon: "app") + L(t: "Share Extension", icon: "app"), + L(t: "Background Fetch", icon: "app") ]), L(t: "多线程", icon: "text.line.first.and.arrowtriangle.forward", sub: [ L(t: "Swift Concurrency",sub: [ @@ -584,6 +585,8 @@ final class GuideListModel { L(t: "启动优化-工具"), L(t: "动态库与静态库"), L(t: "可合并库"), + L(t: "启动优化-线程任务管理"), + L(t: "启动优化-一些技巧"), L(t: "启动优化-测试"), ]), L(t: "包体积", sub: [ diff --git a/SwiftPamphletApp/HomeUI/HomeView.swift b/SwiftPamphletApp/HomeUI/HomeView.swift index 614f20fe..380ea104 100644 --- a/SwiftPamphletApp/HomeUI/HomeView.swift +++ b/SwiftPamphletApp/HomeUI/HomeView.swift @@ -44,7 +44,6 @@ struct HomeView: View { } } } detail: { - if !selectedDataLinkString.isEmpty { DataLink.viewToShow( for: selectedDataLinkString, diff --git a/SwiftPamphletApp/HomeUI/HomeiOSView.swift b/SwiftPamphletApp/HomeUI/HomeiOSView.swift index dba2eb3b..1bfedfbc 100644 --- a/SwiftPamphletApp/HomeUI/HomeiOSView.swift +++ b/SwiftPamphletApp/HomeUI/HomeiOSView.swift @@ -24,6 +24,7 @@ struct HomeiOSView: View { if state == "detail" { DetailView(state: $state) } else { + // 首页 GuideListView() } } diff --git a/SwiftPamphletApp/Performance/TaskManager.swift b/SwiftPamphletApp/Performance/TaskManager.swift index 7220358e..c9c1d175 100644 --- a/SwiftPamphletApp/Performance/TaskManager.swift +++ b/SwiftPamphletApp/Performance/TaskManager.swift @@ -29,62 +29,43 @@ func performLowPriorityTasks(tasks: [@Sendable () async -> Void]) { } func taskgroupDemo() { - var tasks: [@Sendable () async -> Void] = [ - { - await performTaskOne() - }, - { - await performTaskTwo() - }, - { - await performTaskThree() - } - ] - tasks.append { - await wait() - print("Task Four Completed") - } - tasks.append { - await wait() - print("Task Five Completed") + @Sendable func wait() async { +// try? await Task.sleep(nanoseconds: 1_000_000_000) } - // 示例异步任务函数 - @Sendable func performTaskOne() async { + var tasks = [@Sendable () async -> Void]() + tasks.append { await wait() print("Task One Completed") } - - @Sendable func performTaskTwo() async { + tasks.append { await wait() print("Task Two Completed") } - - @Sendable func performTaskThree() async { + tasks.append { await wait() print("Task Three Completed") } - - @Sendable func wait() async { -// try? await Task.sleep(nanoseconds: 1_000_000_000) + tasks.append { + await wait() + print("Task Four Completed") + } + tasks.append { + await wait() + print("Task Five Completed") } // 低优先级示例函数 - @Sendable func backgroundTaskOne() async { + var backgroundTasks = [@Sendable () async -> Void]() + + backgroundTasks.append { await wait() print("Background Task One Executed") } - - @Sendable func backgroundTaskTwo() async { + backgroundTasks.append { await wait() print("Background Task Two Executed") } - - var backgroundTasks: [@Sendable () async -> Void] = [ - { await backgroundTaskOne() }, - { await backgroundTaskTwo() } - ] - backgroundTasks.append { await wait() print("Background Task Three Executed")