diff --git a/README.md b/README.md index 55b51500d..8ba6e6d38 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 戴铭的开发小册子 6.0 -Swift开发的手册,是个 macOS 程序。小册子文字版 《[戴铭的 Swift 小册子](https://ming1016.github.io/2021/11/23/daiming-swift-pamphlet/)》 +Swift开发的手册,是个 macOS 程序,已上线 App Store [点击安装](https://apps.apple.com/cn/app/%E6%88%B4%E9%93%AD%E7%9A%84%E5%BC%80%E5%8F%91%E5%B0%8F%E5%86%8C%E5%AD%90/id1609702529?mt=12),后面更新会方便很多。小册子文字版 《[戴铭的 Swift 小册子](https://ming1016.github.io/2021/11/23/daiming-swift-pamphlet/)》 ![截屏2024-05-07 18 54 42](https://github.com/ming1016/SwiftPamphletApp/assets/251980/9514574b-0f20-4ff5-848c-9b5130f03b81) diff --git a/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift b/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift index 2b4af015c..0fbdbb496 100644 --- a/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift +++ b/SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift @@ -354,7 +354,7 @@ struct EditInfoView: View { // MARK: URL private var urlInputView: some View { HStack { - TextField("地址:", text: $info.url, prompt: Text("输入或粘贴 url,例如 https://www.starming.com")).rounded() + TextField("地址:", text: $info.url, prompt: Text("输入或粘贴 url,例如 https://ming1016.github.io")).rounded() .onSubmit { info.name = "获取标题中......" Task { diff --git a/SwiftPamphletApp/Resource/Guide/1.md b/SwiftPamphletApp/Resource/Guide/1.md index 4e9971a78..f3d034e13 100644 --- a/SwiftPamphletApp/Resource/Guide/1.md +++ b/SwiftPamphletApp/Resource/Guide/1.md @@ -12,5 +12,5 @@ ## 联系作者 - 社交账号:[微博](https://weibo.com/allstarming)、[Mastodon](https://iosdev.space/@starming)、[Github](https://github.com/ming1016) -- 博客:[戴铭的博客](https://starming.com/) +- 博客:[戴铭的博客](https://ming1016.github.io) - 邮箱:[ming1016@foxmail.com](mailto:ming1016@foxmail.com) diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\344\273\213\347\273\215/SwiftUI\346\230\257\344\273\200\344\271\210(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\344\273\213\347\273\215/SwiftUI\346\230\257\344\273\200\344\271\210(ap).md" index 4a1eb72a0..e94f81acc 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\344\273\213\347\273\215/SwiftUI\346\230\257\344\273\200\344\271\210(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\344\273\213\347\273\215/SwiftUI\346\230\257\344\273\200\344\271\210(ap).md" @@ -2,11 +2,11 @@ SwiftUI的布局核心是 GeometryReader、View Preferences和Anchor Preferences。如下图所示: -![](https://starming.com/qdimg/240505/whatisswiftui-ap01.png) +![](https://ming1016.github.io/qdimg/240505/whatisswiftui-ap01.png) SwiftUI的数据流更适合Redux结构,如下图所示: -![](https://starming.com/qdimg/240505/whatisswiftui-ap02.png) +![](https://ming1016.github.io/qdimg/240505/whatisswiftui-ap02.png) 如上图,Redux结构是真正的单向单数据源结构,易于分割,能充分利用SwiftUI内置的数据流Property Wrapper。UI组件干净、体量小、可复用并且无业务逻辑,因此开发时可以聚焦于UI代码。业务逻辑放在一起,所有业务逻辑和数据Model都在Reducer里。 [ACHNBrowserUI](https://github.com/Dimillian/ACHNBrowserUI) 和 [MovieSwiftUI](https://github.com/Dimillian/MovieSwiftUI) 开源项目都是使用的Redux架构。最近比较瞩目的TCA(The Composable Architecture)也是类Redux/Elm的架构的框架, [项目地址见](https://github.com/pointfreeco/swift-composable-architecture) 。 @@ -14,7 +14,7 @@ SwiftUI的数据流更适合Redux结构,如下图所示: 对于SwiftUI,AcFun自研了声明式UI Ysera,类似SwiftUI的接口,并且重构了AcFun里收藏模块列表视图和交互逻辑,如下图所示: -![](https://starming.com/qdimg/240505/whatisswiftui-ap03.png) +![](https://ming1016.github.io/qdimg/240505/whatisswiftui-ap03.png) 通过上图可以看到,swift代码量相比较OC减少了65%以上,原先使用Objective-C实现的相同功能代码超过了1000行,而Swift重写只需要350行,对于AcFun的业务研发工程师而言,同样的需求实现代码比之前少了至少30%,面对单周迭代这样的节奏,团队也变得更从容。代码可读性增加了,后期功能迭代和维护更容易了,Swift让AcFun驶入了iOS开发生态的“快车道”。 diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Image(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Image(ap).md" index 4b7b9cfda..c8869eb20 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Image(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Image(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/image-ap01.png) +![](https://ming1016.github.io/qdimg/240505/image-ap01.png) ```swift struct PlayImageView: View { diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Label(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Label(ap).md" index 2066a4239..d33a31ec1 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Label(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Label(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/label-ap01.png) +![](https://ming1016.github.io/qdimg/240505/label-ap01.png) ```swift struct PlayLabelView: View { diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Text(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Text(ap).md" index 97bf7b0dc..60e7347ab 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Text(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/Text(ap).md" @@ -1,6 +1,6 @@ 基本用法 -![](https://starming.com/qdimg/Text-ap01.png) +![](https://ming1016.github.io/qdimg/Text-ap01.png) ```swift // MARK: - Text diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/TextEditor(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/TextEditor(ap).md" index a664d0679..cf986d79c 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/TextEditor(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/TextEditor(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/texteditor-ap01.png) +![](https://ming1016.github.io/qdimg/240505/texteditor-ap01.png) 对应的代码如下: diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/TextField(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/TextField(ap).md" index aa8d61b57..a6869614b 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/TextField(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\233\276\346\226\207\347\273\204\344\273\266/TextField(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/TextField-ap01.png) +![](https://ming1016.github.io/qdimg/240505/TextField-ap01.png) 使用方法如下: diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/GroupBox(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/GroupBox(ap).md" index f1d3768da..4c8c79af0 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/GroupBox(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/GroupBox(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/groupbox-ap01.png) +![](https://ming1016.github.io/qdimg/240505/groupbox-ap01.png) ```swift struct PlayGroupBoxView: View { diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/Navigation(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/Navigation(ap).md" index 6fbdb4cc1..a23e8aaed 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/Navigation(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/Navigation(ap).md" @@ -132,7 +132,7 @@ struct PNavigationStackDestination: View { 以下是废弃的 NavigationView 的用法。 -![](https://starming.com/qdimg/240505/navigation-ap01.jpeg) +![](https://ming1016.github.io/qdimg/240505/navigation-ap01.jpeg) 对应代码如下: diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/Stack(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/Stack(ap).md" index 33e2d689f..65652d4dc 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/Stack(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\345\270\203\345\261\200\347\273\204\344\273\266/Stack(ap).md" @@ -1,6 +1,6 @@ Stack View 有 VStack、HStack 和 ZStack -![](https://starming.com/qdimg/240505/stack-ap01.jpeg) +![](https://ming1016.github.io/qdimg/240505/stack-ap01.jpeg) ```swift struct PlayStackView: View { diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\346\225\260\346\215\256\351\233\206\345\220\210\347\273\204\344\273\266/LazyVGrid\345\222\214LazyHGrid(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\346\225\260\346\215\256\351\233\206\345\220\210\347\273\204\344\273\266/LazyVGrid\345\222\214LazyHGrid(ap).md" index 1bbb04255..cbf03cc81 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\346\225\260\346\215\256\351\233\206\345\220\210\347\273\204\344\273\266/LazyVGrid\345\222\214LazyHGrid(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\346\225\260\346\215\256\351\233\206\345\220\210\347\273\204\344\273\266/LazyVGrid\345\222\214LazyHGrid(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/lazyvgridandlazyhgrid-ap01.jpeg) +![](https://ming1016.github.io/qdimg/240505/lazyvgridandlazyhgrid-ap01.jpeg) 列的设置有三种,这三种也可以组合用。 diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\346\225\260\346\215\256\351\233\206\345\220\210\347\273\204\344\273\266/List(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\346\225\260\346\215\256\351\233\206\345\220\210\347\273\204\344\273\266/List(ap).md" index c3ec06afd..ec6a76941 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\346\225\260\346\215\256\351\233\206\345\220\210\347\273\204\344\273\266/List(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\346\225\260\346\215\256\351\233\206\345\220\210\347\273\204\344\273\266/List(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/list-ap01.jpeg) +![](https://ming1016.github.io/qdimg/240505/list-ap01.jpeg) List 除了能够展示数据外,还有下拉刷新、过滤搜索和侧滑 Swipe 动作提供更多 Cell 操作的能力。 diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Button(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Button(ap).md" index 26eb4a490..049f3b23f 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Button(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Button(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/button-ap01.png) +![](https://ming1016.github.io/qdimg/240505/button-ap01.png) ```swift struct PlayButtonView: View { diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Picker(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Picker(ap).md" index e984adf23..98b16d88c 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Picker(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Picker(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/picker-ap01.jpeg) +![](https://ming1016.github.io/qdimg/240505/picker-ap01.jpeg) 有 Picker 视图,还有颜色和时间选择的 ColorPicker 和 DatePicker。 diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Toggle(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Toggle(ap).md" index e89ab0f70..42f35404a 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Toggle(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/Toggle(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/toggle-ap01.png) +![](https://ming1016.github.io/qdimg/240505/toggle-ap01.png) Toggle 可以设置 toggleStyle,可以自定义样式。使用示例如下 diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/\346\265\256\345\261\202(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/\346\265\256\345\261\202(ap).md" index 2c0944f9c..9afd54771 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/\346\265\256\345\261\202(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/\346\265\256\345\261\202(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/uplayer-ap01.png) +![](https://ming1016.github.io/qdimg/240505/uplayer-ap01.png) 浮层有 HUD、ContextMenu、Sheet、Alert、ConfirmationDialog、Popover、ActionSheet 等几种方式。这些方式实现代码如下: diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/\350\277\233\345\272\246(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/\350\277\233\345\272\246(ap).md" index eec0f6d68..462a79a21 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/\350\277\233\345\272\246(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\241\250\345\215\225\347\273\204\344\273\266/\350\277\233\345\272\246(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/progress-ap01.jpeg) +![](https://ming1016.github.io/qdimg/240505/progress-ap01.jpeg) 用 ProgressViewStyle 协议,可以创建自定义的进度条视图。在 WatchOS 上会多一个 Guage 视图。 diff --git "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\247\206\350\247\211/SwiftUI Effect(ap).md" "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\247\206\350\247\211/SwiftUI Effect(ap).md" index df3a5ffde..f02788f3f 100644 --- "a/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\247\206\350\247\211/SwiftUI Effect(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/SwiftUI/\350\247\206\350\247\211/SwiftUI Effect(ap).md" @@ -1,4 +1,4 @@ -![](https://starming.com/qdimg/240505/swiftuieffect-ap01.jpeg) +![](https://ming1016.github.io/qdimg/240505/swiftuieffect-ap01.jpeg) ```swift struct PlayEffect: View { diff --git "a/SwiftPamphletApp/Resource/Guide/macOS/\344\270\211\346\240\217\347\273\223\346\236\204(ap).md" "b/SwiftPamphletApp/Resource/Guide/macOS/\344\270\211\346\240\217\347\273\223\346\236\204(ap).md" index df947589f..b94a36804 100644 --- "a/SwiftPamphletApp/Resource/Guide/macOS/\344\270\211\346\240\217\347\273\223\346\236\204(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/macOS/\344\270\211\346\240\217\347\273\223\346\236\204(ap).md" @@ -70,5 +70,5 @@ struct SPList: View { ``` 显示效果如下: -![](https://starming.com/qdimg/240505/threecolumnstructure-ap01.png) +![](https://ming1016.github.io/qdimg/240505/threecolumnstructure-ap01.png) diff --git "a/SwiftPamphletApp/Resource/Guide/\345\237\272\347\241\200\345\272\223/AttributeString(ap).md" "b/SwiftPamphletApp/Resource/Guide/\345\237\272\347\241\200\345\272\223/AttributeString(ap).md" index 449a51f9f..04fba34fd 100644 --- "a/SwiftPamphletApp/Resource/Guide/\345\237\272\347\241\200\345\272\223/AttributeString(ap).md" +++ "b/SwiftPamphletApp/Resource/Guide/\345\237\272\347\241\200\345\272\223/AttributeString(ap).md" @@ -1,6 +1,6 @@ 效果如下: -![](https://starming.com/qdimg/240505/AttributeString-ap01.png) +![](https://ming1016.github.io/qdimg/240505/AttributeString-ap01.png) 代码如下: ```swift