Skip to content

Commit

Permalink
update image url
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed May 8, 2024
1 parent 52a7dec commit a812bb4
Show file tree
Hide file tree
Showing 22 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion SwiftPamphletApp/Resource/Guide/1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 邮箱:[[email protected]](mailto:[email protected])
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

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)

提到数据流就不得不说下苹果公司新出的Combine,对标的是RxSwift,由于是苹果公司官方的库,所以应该优先选择。不过和SwiftUI一样,这两个新库对APP支持最低的系统版本都要求是iOS13及以上。那么怎么能够提前用上SwiftUI和Combine呢?或者说现在使用什么库可以以相同接口方式暂时替换它们,又能在以后改为SwiftUI和Combine时成本最小化呢?

对于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开发生态的“快车道”。

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
基本用法

![](https://starming.com/qdimg/Text-ap01.png)
![](https://ming1016.github.io/qdimg/Text-ap01.png)

```swift
// MARK: - Text
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://starming.com/qdimg/240505/texteditor-ap01.png)
![](https://ming1016.github.io/qdimg/240505/texteditor-ap01.png)

对应的代码如下:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://starming.com/qdimg/240505/TextField-ap01.png)
![](https://ming1016.github.io/qdimg/240505/TextField-ap01.png)

使用方法如下:

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

对应代码如下:

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://starming.com/qdimg/240505/lazyvgridandlazyhgrid-ap01.jpeg)
![](https://ming1016.github.io/qdimg/240505/lazyvgridandlazyhgrid-ap01.jpeg)

列的设置有三种,这三种也可以组合用。

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://starming.com/qdimg/240505/list-ap01.jpeg)
![](https://ming1016.github.io/qdimg/240505/list-ap01.jpeg)

List 除了能够展示数据外,还有下拉刷新、过滤搜索和侧滑 Swipe 动作提供更多 Cell 操作的能力。

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://starming.com/qdimg/240505/picker-ap01.jpeg)
![](https://ming1016.github.io/qdimg/240505/picker-ap01.jpeg)

有 Picker 视图,还有颜色和时间选择的 ColorPicker 和 DatePicker。

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://starming.com/qdimg/240505/toggle-ap01.png)
![](https://ming1016.github.io/qdimg/240505/toggle-ap01.png)

Toggle 可以设置 toggleStyle,可以自定义样式。使用示例如下

Expand Down
Original file line number Diff line number Diff line change
@@ -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 等几种方式。这些方式实现代码如下:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://starming.com/qdimg/240505/progress-ap01.jpeg)
![](https://ming1016.github.io/qdimg/240505/progress-ap01.jpeg)

用 ProgressViewStyle 协议,可以创建自定义的进度条视图。在 WatchOS 上会多一个 Guage 视图。

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion SwiftPamphletApp/Resource/Guide/macOS/三栏结构(ap).md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ struct SPList: View {
```

显示效果如下:
![](https://starming.com/qdimg/240505/threecolumnstructure-ap01.png)
![](https://ming1016.github.io/qdimg/240505/threecolumnstructure-ap01.png)

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
效果如下:

![](https://starming.com/qdimg/240505/AttributeString-ap01.png)
![](https://ming1016.github.io/qdimg/240505/AttributeString-ap01.png)

代码如下:
```swift
Expand Down

0 comments on commit a812bb4

Please sign in to comment.