Skip to content

Commit 814449c

Browse files
committed
重构资料整理,使用 SwiftData,WIP
1 parent ce5c18b commit 814449c

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed

SwiftPamphletApp.xcodeproj/project.pbxproj

+20
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
08038767276700F100519B15 /* CCYRESTfulAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08038766276700F100519B15 /* CCYRESTfulAPI.swift */; };
2828
083554E12756503B0095E0EE /* AnimateLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 083554E02756503B0095E0EE /* AnimateLayout.swift */; };
2929
083554E327572BB60095E0EE /* AppVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 083554E227572BB60095E0EE /* AppVM.swift */; };
30+
08397E232B9EE8F400DFDD02 /* InfoDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */; };
31+
08397E252B9EEE1300DFDD02 /* InfoListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E242B9EEE1300DFDD02 /* InfoListView.swift */; };
32+
08397E272B9EF37600DFDD02 /* InfosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E262B9EF37600DFDD02 /* InfosView.swift */; };
3033
084417752B99B9060049297D /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 084417742B99B9060049297D /* HomeView.swift */; };
3134
084417772B99BA3F0049297D /* SidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 084417762B99BA3F0049297D /* SidebarView.swift */; };
3235
084417792B99BE720049297D /* DataLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 084417782B99BE720049297D /* DataLink.swift */; };
@@ -280,6 +283,9 @@
280283
08038766276700F100519B15 /* CCYRESTfulAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCYRESTfulAPI.swift; sourceTree = "<group>"; };
281284
083554E02756503B0095E0EE /* AnimateLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimateLayout.swift; sourceTree = "<group>"; };
282285
083554E227572BB60095E0EE /* AppVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppVM.swift; sourceTree = "<group>"; };
286+
08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoDataModel.swift; sourceTree = "<group>"; };
287+
08397E242B9EEE1300DFDD02 /* InfoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoListView.swift; sourceTree = "<group>"; };
288+
08397E262B9EF37600DFDD02 /* InfosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfosView.swift; sourceTree = "<group>"; };
283289
084417742B99B9060049297D /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
284290
084417762B99BA3F0049297D /* SidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarView.swift; sourceTree = "<group>"; };
285291
084417782B99BE720049297D /* DataLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataLink.swift; sourceTree = "<group>"; };
@@ -552,6 +558,16 @@
552558
path = Network;
553559
sourceTree = "<group>";
554560
};
561+
08397E212B9EE83F00DFDD02 /* InfoOrganizer */ = {
562+
isa = PBXGroup;
563+
children = (
564+
08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */,
565+
08397E242B9EEE1300DFDD02 /* InfoListView.swift */,
566+
08397E262B9EF37600DFDD02 /* InfosView.swift */,
567+
);
568+
path = InfoOrganizer;
569+
sourceTree = "<group>";
570+
};
555571
08401CDD28BF7F0900883D8B /* 新鲜事 */ = {
556572
isa = PBXGroup;
557573
children = (
@@ -1053,6 +1069,7 @@
10531069
086A5F052744E88E00FECE02 /* SwiftPamphletApp */ = {
10541070
isa = PBXGroup;
10551071
children = (
1072+
08397E212B9EE83F00DFDD02 /* InfoOrganizer */,
10561073
08ED801A2B9D1EDA0069B7EC /* Setting */,
10571074
080124FD27EC62DC00E44222 /* SwiftPamphletAppDebug.entitlements */,
10581075
08CD61FB27758B22008C0935 /* Core */,
@@ -1572,11 +1589,13 @@
15721589
08BE635A27C6575C002BC6A8 /* PlayGroupBoxView.swift in Sources */,
15731590
08BF26D8276B5D7F0064DDAC /* ExploreRepoListView.swift in Sources */,
15741591
088EE8F527BD24E000764525 /* PlayLinkView.swift in Sources */,
1592+
08397E232B9EE8F400DFDD02 /* InfoDataModel.swift in Sources */,
15751593
084417792B99BE720049297D /* DataLink.swift in Sources */,
15761594
08522BEB27CF7744005FF059 /* PlayKeyboard.swift in Sources */,
15771595
08C3BBA427CF1B7B00ACF0FE /* PlayPickerView.swift in Sources */,
15781596
08448F4B279E872B00B61353 /* GuideView.swift in Sources */,
15791597
08BE635027C4C0F2002BC6A8 /* PlayFormView.swift in Sources */,
1598+
08397E252B9EEE1300DFDD02 /* InfoListView.swift in Sources */,
15801599
086A5F402744EDCE00FECE02 /* RepoVM.swift in Sources */,
15811600
08BE636627C88750002BC6A8 /* PlayProgressView.swift in Sources */,
15821601
084417772B99BA3F0049297D /* SidebarView.swift in Sources */,
@@ -1602,6 +1621,7 @@
16021621
08522BD827CF344B005FF059 /* PlaySliderView.swift in Sources */,
16031622
086A5F362744ED9600FECE02 /* RepoView.swift in Sources */,
16041623
086A5F302744ED8600FECE02 /* IssuesListFromCustomView.swift in Sources */,
1624+
08397E272B9EF37600DFDD02 /* InfosView.swift in Sources */,
16051625
08C3BB7E27CE3EBD00ACF0FE /* PlayTabView.swift in Sources */,
16061626
084417752B99B9060049297D /* HomeView.swift in Sources */,
16071627
08449034279F6D0D00B61353 /* RepoWebView.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// InfoDataModel.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/3/11.
6+
//
7+
8+
import Foundation
9+
import SwiftData
10+
11+
@Model
12+
class IOInfo {
13+
var name: String = ""
14+
var url: String = ""
15+
var des: String = ""
16+
var category: IOCategory?
17+
18+
var createDate: Date
19+
var updateDate: Date
20+
21+
init(name: String,
22+
url: String,
23+
des: String,
24+
category: IOCategory? = nil,
25+
createDate: Date,
26+
updateDate: Date
27+
) {
28+
self.name = name
29+
self.url = url
30+
self.des = des
31+
self.category = category
32+
self.createDate = createDate
33+
self.updateDate = updateDate
34+
}
35+
}
36+
37+
@Model
38+
class IOCategory {
39+
var name: String = ""
40+
var infos: [IOInfo]? = [IOInfo]()
41+
42+
var createDate: Date
43+
var updateDate: Date
44+
45+
init(name: String,
46+
createDate: Date,
47+
updateDate: Date
48+
) {
49+
self.name = name
50+
self.createDate = createDate
51+
self.updateDate = updateDate
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// InfoListView.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/3/11.
6+
//
7+
8+
import SwiftUI
9+
import SwiftData
10+
11+
struct InfoListView: View {
12+
@Environment(\.modelContext) var modelContext
13+
@State private var path = NavigationPath()
14+
@State private var searchText = ""
15+
@State private var sortOrder = [SortDescriptor(\IOInfo.updateDate)]
16+
17+
var body: some View {
18+
NavigationStack(path: $path) {
19+
InfosView(searchString: searchText, sortOrder: sortOrder)
20+
.navigationTitle("资料列表")
21+
.navigationDestination(for: IOInfo.self) { info in
22+
// TODO:
23+
}
24+
}
25+
}
26+
}
27+
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// InfosView.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/3/11.
6+
//
7+
8+
import SwiftUI
9+
import SwiftData
10+
11+
struct InfosView: View {
12+
@Environment(\.modelContext) var modelContext
13+
@Query var infos: [IOInfo]
14+
init(searchString: String = "", sortOrder:[SortDescriptor<IOInfo>] = []) {
15+
_infos = Query(filter: #Predicate { info in
16+
if searchString.isEmpty {
17+
true
18+
} else {
19+
info.name.localizedStandardContains(searchString)
20+
|| info.url.localizedStandardContains(searchString)
21+
|| info.des.localizedStandardContains(searchString)
22+
}
23+
}, sort: sortOrder)
24+
}
25+
26+
var body: some View {
27+
List {
28+
ForEach(infos) { info in
29+
NavigationLink(value: info) {
30+
Text(info.name)
31+
}
32+
}
33+
.onDelete(perform: { indexSet in
34+
deleteInfos(at: indexSet)
35+
})
36+
}
37+
}
38+
39+
func deleteInfos(at offsets: IndexSet) {
40+
for offset in offsets {
41+
let info = infos[offset]
42+
modelContext.delete(info)
43+
}
44+
}
45+
}
46+

SwiftPamphletApp/SwiftPamphletAppApp.swift

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import SwiftUI
99
import Combine
1010
import SMNetwork
11+
import SwiftData
1112

1213
@main
1314
struct SwiftPamphletAppApp: App {
@@ -17,6 +18,7 @@ struct SwiftPamphletAppApp: App {
1718
WindowGroup {
1819
SwiftPamphletApp()
1920
// HomeView()
21+
// .modelContainer(for: [IOInfo.self])
2022
// Demo()
2123
}
2224
.windowToolbarStyle(UnifiedWindowToolbarStyle(showsTitle: true)) // 用来控制是否展示标题

0 commit comments

Comments
 (0)