Skip to content

Commit

Permalink
性能示例
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Nov 12, 2024
1 parent 5d3e534 commit dfdf419
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Swift开发的手册,是个 macOS 程序,已上线macOS应用商店,[点

- 手册书签收藏
- 资料收集整理(参考[我是怎么做个人知识管理(PKM)的,从史前时代备忘录、Sublime,经历了Evernote,Markdown兴起,Bear的优雅,Notion革命,飞书语雀,Obsidian、Flomo,到最后使用卢曼卡片盒笔记法串起了流程](https://mp.weixin.qq.com/s/PbUOxURK57eIeSnuE1mh4g)这篇文章,里面有提及如何使用小册子的资料整理功能)
- 离线保存资料
- 资料网页离线保存(防止网络资料源丢失)
- 知识点和资料关联
- 手册内容和资料可搜索
- Github 开发者和仓库信息添加管理
- Github 开发者和仓库信息添加管理(在设置里添加 token)

本应用知识点目前主要有 Swift 基础语法,SwiftUI,SwiftData,小组件等知识内容。更多 iOS 开发资料,信息以及开发者活动可以关注 [XR 基地](https://xreality.zone)[SwiftGG](https://swiftgg.team)。SwiftGG 的愿景是致力于成为中国与海外技术社区的桥梁,为中国开发者创造展示自我走向世界舞台的机会。

Expand Down
32 changes: 28 additions & 4 deletions SwiftPamphletApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
0851E56D2C8711DA00D9463A /* OC运行时(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 0851E56C2C8711DA00D9463A /* OC运行时(ap).md */; };
0851E5702C872A7A00D9463A /* CPU占用率(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 0851E56F2C872A7A00D9463A /* CPU占用率(ap).md */; };
0851E5722C872AD100D9463A /* CPU核数和类型(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 0851E5712C872AD100D9463A /* CPU核数和类型(ap).md */; };
0851E5772C87478700D9463A /* 启动优化-启动时间(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 0851E5762C87478700D9463A /* 启动优化-启动时间(ap).md */; };
0851E5792C87563100D9463A /* 截获网络请求数据(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 0851E5782C87563100D9463A /* 截获网络请求数据(ap).md */; };
0868D00B2BDD37280023C871 /* SMGitHub in Frameworks */ = {isa = PBXBuildFile; productRef = 0868D00A2BDD37280023C871 /* SMGitHub */; };
086A5F072744E88E00FECE02 /* SwiftPamphletAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 086A5F062744E88E00FECE02 /* SwiftPamphletAppApp.swift */; };
Expand Down Expand Up @@ -489,6 +488,11 @@
3AE0D59A2BAB0A0600D6D925 /* DeveloperListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE0D5992BAB0A0600D6D925 /* DeveloperListView.swift */; };
3AE0D59E2BAB183100D6D925 /* EditDeveloper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE0D59D2BAB183100D6D925 /* EditDeveloper.swift */; };
3AE4CA382BD7813D005BEF2C /* InfoOrganizer in Frameworks */ = {isa = PBXBuildFile; productRef = 3AE4CA372BD7813D005BEF2C /* InfoOrganizer */; };
3AEC7F4B2CE37028005D510D /* 动态库与静态库(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 3AEC7F4A2CE37028005D510D /* 动态库与静态库(ap).md */; };
3AEC7F4D2CE373C5005D510D /* 启动优化-测试(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 3AEC7F4C2CE373C5005D510D /* 启动优化-测试(ap).md */; };
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 */; };
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 */; };
Expand Down Expand Up @@ -618,7 +622,6 @@
0851E56C2C8711DA00D9463A /* OC运行时(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "OC运行时(ap).md"; sourceTree = "<group>"; };
0851E56F2C872A7A00D9463A /* CPU占用率(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "CPU占用率(ap).md"; sourceTree = "<group>"; };
0851E5712C872AD100D9463A /* CPU核数和类型(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "CPU核数和类型(ap).md"; sourceTree = "<group>"; };
0851E5762C87478700D9463A /* 启动优化-启动时间(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "启动优化-启动时间(ap).md"; sourceTree = "<group>"; };
0851E5782C87563100D9463A /* 截获网络请求数据(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "截获网络请求数据(ap).md"; sourceTree = "<group>"; };
0869233F2BF2BF81006779A3 /* AVKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVKit.framework; path = System/Library/Frameworks/AVKit.framework; sourceTree = SDKROOT; };
086A5F032744E88E00FECE02 /* 戴铭的开发小册子.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "戴铭的开发小册子.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -969,6 +972,11 @@
3ADBA8502CE216E900B0050B /* Perf.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Perf.swift; sourceTree = "<group>"; };
3AE0D5992BAB0A0600D6D925 /* DeveloperListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperListView.swift; sourceTree = "<group>"; };
3AE0D59D2BAB183100D6D925 /* EditDeveloper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditDeveloper.swift; sourceTree = "<group>"; };
3AEC7F4A2CE37028005D510D /* 动态库与静态库(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "动态库与静态库(ap).md"; sourceTree = "<group>"; };
3AEC7F4C2CE373C5005D510D /* 启动优化-测试(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "启动优化-测试(ap).md"; sourceTree = "<group>"; };
3AEC7F572CE38749005D510D /* OC项目启动时间(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "OC项目启动时间(ap).md"; sourceTree = "<group>"; };
3AEC7F5A2CE3876D005D510D /* Swift项目启动时间(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Swift项目启动时间(ap).md"; sourceTree = "<group>"; };
3AEC7F5C2CE39250005D510D /* 可合并库(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "可合并库(ap).md"; sourceTree = "<group>"; };
3AF2A2DE2BE22A8C00F3BE1B /* UnCategoryInfoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnCategoryInfoListView.swift; sourceTree = "<group>"; };
3AF2A2E02BE22B5800F3BE1B /* UnCategoryInfosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnCategoryInfosView.swift; sourceTree = "<group>"; };
3AF2A2E22BE2317300F3BE1B /* StarInfoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarInfoListView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1302,9 +1310,12 @@
0851E5752C87475100D9463A /* 启动优化 */ = {
isa = PBXGroup;
children = (
0851E5762C87478700D9463A /* 启动优化-启动时间(ap).md */,
3AEC7F582CE38749005D510D /* 启动时间 */,
088F2C282C88438F00DCA64F /* 启动治理思路(ap).md */,
088F2C2A2C8843E000DCA64F /* 启动优化-工具(ap).md */,
3AEC7F4A2CE37028005D510D /* 动态库与静态库(ap).md */,
3AEC7F5C2CE39250005D510D /* 可合并库(ap).md */,
3AEC7F4C2CE373C5005D510D /* 启动优化-测试(ap).md */,
);
path = "启动优化";
sourceTree = "<group>";
Expand Down Expand Up @@ -2292,6 +2303,15 @@
path = Developer;
sourceTree = "<group>";
};
3AEC7F582CE38749005D510D /* 启动时间 */ = {
isa = PBXGroup;
children = (
3AEC7F572CE38749005D510D /* OC项目启动时间(ap).md */,
3AEC7F5A2CE3876D005D510D /* Swift项目启动时间(ap).md */,
);
path = "启动时间";
sourceTree = "<group>";
};
3AF2A2DB2BE227C700F3BE1B /* UnCategoryInfos */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2441,7 +2461,7 @@
08BDD5C22C6B007A00914412 /* Table-样式(ap).md in Resources */,
08F51BC527A374A500693AB6 /* footer_js.html in Resources */,
08BDD5552C6B007A00914412 /* macOS技术演进(ap).md in Resources */,
0851E5772C87478700D9463A /* 启动优化-启动时间(ap).md in Resources */,
3AEC7F4B2CE37028005D510D /* 动态库与静态库(ap).md in Resources */,
083266982C97E62F00E27CC5 /* 人工智能-语音(ap).md in Resources */,
08BDD5882C6B007A00914412 /* confirmationDialog()(ap).md in Resources */,
08BDD58C2C6B007A00914412 /* Popover(ap).md in Resources */,
Expand Down Expand Up @@ -2523,6 +2543,7 @@
08BDD5682C6B007A00914412 /* Form(ap).md in Resources */,
088F2C272C8836B200DCA64F /* 崩溃日志(ap).md in Resources */,
08BDD5412C6B007A00914412 /* 小组件-参考资料(ap).md in Resources */,
3AEC7F5D2CE39250005D510D /* 可合并库(ap).md in Resources */,
08BDD5092C6B007A00914412 /* Combine Timer(ap).md in Resources */,
083266752C96C00F00E27CC5 /* visionOS-空间设计(ap).md in Resources */,
08448FAD279EC2E900B61353 /* 泛型和协议(ap).md in Resources */,
Expand Down Expand Up @@ -2645,6 +2666,7 @@
08F0F8B12C95964400DC659B /* 开源-有趣的项目(ap).md in Resources */,
08BDD5C02C6B007A00914412 /* Table-多属性排序(ap).md in Resources */,
08BDD5902C6B007A00914412 /* SwiftUI是什么(ap).md in Resources */,
3AEC7F4D2CE373C5005D510D /* 启动优化-测试(ap).md in Resources */,
08BDD5352C6B007A00914412 /* 随机(ap).md in Resources */,
08BDD5A42C6B007A00914412 /* Previews协议(ap).md in Resources */,
08BDD5012C6B007A00914412 /* KeyframeAnimator(ap).md in Resources */,
Expand Down Expand Up @@ -2752,6 +2774,7 @@
08BDD5782C6B007A00914412 /* ViewThatFits(ap).md in Resources */,
088F2C3A2C93296200DCA64F /* 笔记记录方法(ap).md in Resources */,
088F2C3E2C9329E400DCA64F /* PARA记录法(ap).md in Resources */,
3AEC7F5B2CE3876D005D510D /* Swift项目启动时间(ap).md in Resources */,
08BDD57A2C6B007A00914412 /* 自定义导航栏(ap).md in Resources */,
08BDD5B92C6B007A00914412 /* List(ap).md in Resources */,
08BDD56B2C6B007A00914412 /* Toggle(ap).md in Resources */,
Expand All @@ -2762,6 +2785,7 @@
0832667D2C96C18100E27CC5 /* ARKit(ap).md in Resources */,
08BDD5942C6B007A00914412 /* SwiftCharts(ap).md in Resources */,
08448FE8279EC84B00B61353 /* 恒等(ap).md in Resources */,
3AEC7F592CE38749005D510D /* OC项目启动时间(ap).md in Resources */,
083266A42C987D9000E27CC5 /* macOS开源-菜单栏(ap).md in Resources */,
084DBA122C6DA52D00C9D88D /* 日期组件(ap).md in Resources */,
08BDD58E2C6B007A00914412 /* SwiftUI参考资料(ap).md in Resources */,
Expand Down
9 changes: 5 additions & 4 deletions SwiftPamphletApp/App/SwiftPamphletAppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SMFile
import SMGitHub
import os.signpost
import BackgroundTasks
import AppIntents

@main
struct SwiftPamphletAppApp: App {
Expand Down Expand Up @@ -54,9 +55,8 @@ struct SwiftPamphletAppApp: App {
}
scheduleAppRefresh()

// 任务管理器
// 使用示例

// 任务管理器示例
taskgroupDemo()

#if DEBUG
// 主界面加载完成,记录终点
Expand All @@ -83,7 +83,6 @@ struct SwiftPamphletAppApp: App {
break
}
}

// .modelContainer(for: [IOInfo.self, DeveloperModel.self, BookmarkModel.self], isUndoEnabled: true)
#endif
}
Expand All @@ -98,6 +97,8 @@ struct SwiftPamphletAppApp: App {

}



#if os(iOS)
// MARK: - Background Task
func scheduleAppRefresh() {
Expand Down
10 changes: 7 additions & 3 deletions SwiftPamphletApp/Guide/View/GuideListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,7 @@ final class GuideListModel {
L(t: "Swift-DocC", icon: "doc.append"),
L(t: "AppIcon", icon: "app"),
L(t: "Share Extension", icon: "app")

]),

L(t: "多线程", icon: "text.line.first.and.arrowtriangle.forward", sub: [
L(t: "Swift Concurrency",sub: [
L(t: "Swift Concurrency是什么"),
Expand Down Expand Up @@ -578,9 +576,15 @@ final class GuideListModel {
L(t: "CPU核数和类型"),
]),
L(t: "启动优化", sub: [
L(t: "启动优化-启动时间"),
L(t: "启动时间",sub: [
L(t: "OC项目启动时间"),
L(t: "Swift项目启动时间"),
]),
L(t: "启动治理思路"),
L(t: "启动优化-工具"),
L(t: "动态库与静态库"),
L(t: "可合并库"),
L(t: "启动优化-测试"),
]),
L(t: "包体积", sub: [
L(t: "包体积的影响"),
Expand Down
31 changes: 30 additions & 1 deletion SwiftPamphletApp/HomeUI/HomeiOSView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,37 @@
import SwiftUI

struct HomeiOSView: View {
@State var state: String = ""
var body: some View {
GuideListView()
EmptyView()
.onOpenURL { url in
if let content = URLComponents(url: url, resolvingAgainstBaseURL: true)?
.queryItems?.first(where: { $0.name == "content" })?.value {
if content == "detail" {
state = "detail"
} else {
state = ""
}
}
}
if state == "detail" {
DetailView(state: $state)
} else {
GuideListView()
}
}
}

struct DetailView: View {
@Binding var state: String
var body: some View {
VStack {
Text("Detail View here")
Button(action: {
state = ""
}) {
Text("Back")
}
}
}
}
11 changes: 11 additions & 0 deletions SwiftPamphletApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
<array>
<string>zh</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>SwiftPamphletApp</string>
</array>
</dict>
</array>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
Expand Down
99 changes: 99 additions & 0 deletions SwiftPamphletApp/Performance/TaskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,104 @@

import Foundation

// 按组执行异步任务
func executeTasksConcurrently(tasks: [@Sendable () async -> Void]) async {
await withTaskGroup(of: Void.self) { group in
// 将每个任务闭包添加到任务组中
for task in tasks {
group.addTask {
await task()
}
}
}
}

// 执行低优先级任务
func performLowPriorityTasks(tasks: [@Sendable () async -> Void]) {
for task in tasks {
Task.detached(priority: .background) {
await task()
}
}
}

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 performTaskOne() async {
await wait()
print("Task One Completed")
}

@Sendable func performTaskTwo() async {
await wait()
print("Task Two Completed")
}

@Sendable func performTaskThree() async {
await wait()
print("Task Three Completed")
}

@Sendable func wait() async {
// try? await Task.sleep(nanoseconds: 1_000_000_000)
}

// 低优先级示例函数
@Sendable func backgroundTaskOne() async {
await wait()
print("Background Task One Executed")
}

@Sendable func backgroundTaskTwo() async {
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")
}
backgroundTasks.append {
await wait()
print("Background Task Four Executed")
}

// 开始执行任务
performLowPriorityTasks(tasks: backgroundTasks)
Task {
await executeTasksConcurrently(tasks: tasks)
print("first group of tasks completed.")
await executeTasksConcurrently(tasks: tasks)
print("second group of tasks completed.")
await executeTasksConcurrently(tasks: tasks)
print("third group of tasks completed.")
print("All tasks completed.")
}
}


0 comments on commit dfdf419

Please sign in to comment.