File tree Expand file tree Collapse file tree 9 files changed +78
-27
lines changed Expand file tree Collapse file tree 9 files changed +78
-27
lines changed Original file line number Diff line number Diff line change 38
38
E8548E8C2AC45EDD00809E08 /* ToDoEditor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToDoEditor.swift; sourceTree = "<group>"; };
39
39
E8548E8D2AC45EDD00809E08 /* ToDoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToDoCell.swift; sourceTree = "<group>"; };
40
40
E8548E8E2AC45EDD00809E08 /* ToDoListsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToDoListsView.swift; sourceTree = "<group>"; };
41
+ E8F59F782AC6158700E01163 /* ManagedToDos.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = ManagedToDos.xctestplan; sourceTree = "<group>"; };
41
42
/* End PBXFileReference section */
42
43
43
44
/* Begin PBXFrameworksBuildPhase section */
55
56
E8548E592AC454F000809E08 = {
56
57
isa = PBXGroup;
57
58
children = (
59
+ E8F59F782AC6158700E01163 /* ManagedToDos.xctestplan */,
58
60
E8548E7B2AC455D500809E08 /* README.md */,
59
61
E8548E642AC454F000809E08 /* ManagedToDos */,
60
62
E8548E632AC454F000809E08 /* Products */,
425
427
repositoryURL = "git@github.com:Data-swift/ManagedModels.git";
426
428
requirement = {
427
429
kind = upToNextMajorVersion;
428
- minimumVersion = 0.5.2 ;
430
+ minimumVersion = 0.6.0 ;
429
431
};
430
432
};
431
433
/* End XCRemoteSwiftPackageReference section */
Original file line number Diff line number Diff line change
1
+ {
2
+ "configurations" : [
3
+ {
4
+ "id" : "AB016975-AF24-4306-B5DC-F5E394956E9D",
5
+ "name" : "Test Scheme Action",
6
+ "options" : {
7
+
8
+ }
9
+ }
10
+ ],
11
+ "defaultOptions" : {
12
+ "codeCoverage" : false,
13
+ "targetForVariableExpansion" : {
14
+ "containerPath" : "container:ManagedToDos.xcodeproj",
15
+ "identifier" : "E8548E612AC454F000809E08",
16
+ "name" : "ManagedToDos"
17
+ }
18
+ },
19
+ "testTargets" : [
20
+ {
21
+ "target" : {
22
+ "containerPath" : "container:..\/..\/..\/..\/dev\/Swift\/Data.swift\/ManagedModels",
23
+ "identifier" : "ManagedModelMacrosTests",
24
+ "name" : "ManagedModelMacrosTests"
25
+ }
26
+ },
27
+ {
28
+ "target" : {
29
+ "containerPath" : "container:..\/..\/..\/..\/dev\/Swift\/Data.swift\/ManagedModels",
30
+ "identifier" : "ManagedModelTests",
31
+ "name" : "ManagedModelTests"
32
+ }
33
+ }
34
+ ],
35
+ "version" : 1
36
+ }
Original file line number Diff line number Diff line change @@ -16,17 +16,29 @@ final class ToDo: NSManagedObject {
16
16
17
17
var title : String
18
18
var isDone : Bool
19
- var priority : Int
19
+ var priority : Priority
20
20
var created : Date
21
21
var due : Date ?
22
22
var list : ToDoList
23
23
24
+ enum Priority : Int , Comparable , CaseIterable {
25
+ case veryLow = 1
26
+ case low = 2
27
+ case medium = 3
28
+ case high = 4
29
+ case veryHigh = 5
30
+
31
+ static func < ( lhs: Self , rhs: Self ) -> Bool {
32
+ lhs. rawValue < rhs. rawValue
33
+ }
34
+ }
35
+
24
36
convenience init ( list : ToDoList ,
25
37
title : String ,
26
- isDone : Bool = false ,
27
- priority : Int = 3 ,
28
- created : Date = Date ( ) ,
29
- due : Date ? = nil )
38
+ isDone : Bool = false ,
39
+ priority : Priority = . medium ,
40
+ created : Date = Date ( ) ,
41
+ due : Date ? = nil )
30
42
{
31
43
// This is important so that the objects don't end up in different
32
44
// contexts.
Original file line number Diff line number Diff line change @@ -14,13 +14,12 @@ import ManagedModels
14
14
@Model
15
15
final class ToDoList : NSManagedObject {
16
16
17
- var title : String
18
- var toDos : Set < ToDo > // currently can't use ` [ ToDo ]` here.
19
-
17
+ var title = " "
18
+ var toDos = [ ToDo ] ( )
19
+
20
20
convenience init ( title: String ) {
21
21
self . init ( )
22
22
self . title = title
23
- self . toDos = [ ]
24
23
}
25
24
26
25
var hasOverdueItems : Bool { toDos. contains { $0. isOverDue && !$0. isDone } }
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ enum PreviewData {
31
31
// The insert is not even necessary, done by init
32
32
ctx. insert ( ToDo ( list: list, title: " Apples " ) )
33
33
ctx. insert ( ToDo ( list: list, title: " Oranges " ) )
34
- ctx. insert ( ToDo ( list: list, title: " Juice " , priority: 4 ) )
34
+ ctx. insert ( ToDo ( list: list, title: " Juice " , priority: . high ) )
35
35
}
36
36
do {
37
37
let list = ToDoList ( title: " To-Do's " )
@@ -41,7 +41,7 @@ enum PreviewData {
41
41
ctx. insert ( ToDo ( list: list, title: " Wash 🚗 " ,
42
42
due: Date ( ) . advanced ( by: 7200 ) ) )
43
43
ctx. insert ( ToDo ( list: list, title: " Rebuild SwiftData " ,
44
- priority: 2 ,
44
+ priority: . low ,
45
45
due: Date ( ) . advanced ( by: - 7200 ) ) )
46
46
ctx. insert ( ToDo ( list: list, title: " Do Groceries " ) )
47
47
}
Original file line number Diff line number Diff line change @@ -51,14 +51,14 @@ struct ToDoCell: View {
51
51
52
52
Spacer ( )
53
53
54
- if toDo. priority == 4 { Text ( " ❗️ " ) }
55
- else if toDo. priority > 4 { Text ( " ‼️ " ) }
54
+ if toDo. priority == . high { Text ( " ❗️ " ) }
55
+ else if toDo. priority >= . veryHigh { Text ( " ‼️ " ) }
56
56
}
57
57
58
58
if let due = toDo. due {
59
59
Text ( " \( due, format: . dateTime) " )
60
60
. font ( . footnote)
61
- . foregroundColor ( toDo. isOverDue && toDo. priority > 2
61
+ . foregroundColor ( toDo. isOverDue && toDo. priority > . low
62
62
? . red : nil )
63
63
}
64
64
}
Original file line number Diff line number Diff line change @@ -53,14 +53,13 @@ struct ToDoEditor: View {
53
53
54
54
if !toDo. isDone {
55
55
Picker ( " Priority " , selection: $toDo. priority) {
56
- ForEach ( 1 ... 5 , id: \. self) { priority in
56
+ ForEach ( ToDo . Priority . allCases , id: \. self) { priority in
57
57
switch priority {
58
- case 1 : Text ( " Very low " )
59
- case 2 : Text ( " Low " )
60
- case 3 : Text ( " Medium " )
61
- case 4 : Text ( " High " )
62
- case 5 : Text ( " Very High " )
63
- default : Text ( " \( priority) " )
58
+ case . veryLow : Text ( " Very low " )
59
+ case . low : Text ( " Low " )
60
+ case . medium : Text ( " Medium " )
61
+ case . high : Text ( " High " )
62
+ case . veryHigh : Text ( " Very High " )
64
63
}
65
64
}
66
65
}
Original file line number Diff line number Diff line change @@ -35,10 +35,10 @@ struct ToDoListView: View {
35
35
_toDos = . init(
36
36
filter: NSPredicate ( format: " list = %@ " , toDoList) ,
37
37
sort: [
38
- SortDescriptor ( \ ToDo . isDone, order: . forward) ,
39
- SortDescriptor ( \ ToDo . priority, order: . reverse) ,
40
- SortDescriptor ( \ ToDo . due, order: . forward) ,
41
- SortDescriptor ( \ ToDo . created, order: . reverse)
38
+ . init ( \ . isDone, order: . forward) ,
39
+ . init ( \ . priority, order: . reverse) ,
40
+ . init ( \ . due, order: . forward) ,
41
+ . init ( \ . created, order: . reverse)
42
42
] ,
43
43
animation: . default
44
44
)
@@ -47,7 +47,7 @@ struct ToDoListView: View {
47
47
// MARK: - Actions
48
48
49
49
private func addItem( ) {
50
- let toDo = ToDo ( list: toDoList, title: " " , priority: 3 )
50
+ let toDo = ToDo ( list: toDoList, title: " " , priority: . medium )
51
51
navigationPath. append ( toDo)
52
52
try ? viewContext. save ( )
53
53
}
Original file line number Diff line number Diff line change 9
9
[ ManagedModels] ( https://github.com/Data-swift/ManagedModels/ ) ,
10
10
which adds some SwiftData-like ` @Model ` support to regular CoreData.
11
11
12
+ Blog article describing ManagedModels: [ ` @Model ` for CoreData] ( https://www.alwaysrightinstitute.com/managedmodels/ ) .
13
+
12
14
13
15
### Models
14
16
@@ -56,6 +58,7 @@ ManagedModels has no other dependencies.
56
58
#### Links
57
59
58
60
- [ ManagedModels] ( https://github.com/Data-swift/ManagedModels/ )
61
+ - Blog article: [ ` @Model ` for CoreData] ( https://www.alwaysrightinstitute.com/managedmodels/ ) .
59
62
- Apple:
60
63
- [ CoreData] ( https://developer.apple.com/documentation/coredata )
61
64
- [ SwiftData] ( https://developer.apple.com/documentation/swiftdata )
You can’t perform that action at this time.
0 commit comments