Skip to content

Commit 9c61f0d

Browse files
committed
Merge branch 'develop'
2 parents 8549e0b + a7a4659 commit 9c61f0d

File tree

9 files changed

+78
-27
lines changed

9 files changed

+78
-27
lines changed

ManagedToDos.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
E8548E8C2AC45EDD00809E08 /* ToDoEditor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToDoEditor.swift; sourceTree = "<group>"; };
3939
E8548E8D2AC45EDD00809E08 /* ToDoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToDoCell.swift; sourceTree = "<group>"; };
4040
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>"; };
4142
/* End PBXFileReference section */
4243

4344
/* Begin PBXFrameworksBuildPhase section */
@@ -55,6 +56,7 @@
5556
E8548E592AC454F000809E08 = {
5657
isa = PBXGroup;
5758
children = (
59+
E8F59F782AC6158700E01163 /* ManagedToDos.xctestplan */,
5860
E8548E7B2AC455D500809E08 /* README.md */,
5961
E8548E642AC454F000809E08 /* ManagedToDos */,
6062
E8548E632AC454F000809E08 /* Products */,
@@ -425,7 +427,7 @@
425427
repositoryURL = "git@github.com:Data-swift/ManagedModels.git";
426428
requirement = {
427429
kind = upToNextMajorVersion;
428-
minimumVersion = 0.5.2;
430+
minimumVersion = 0.6.0;
429431
};
430432
};
431433
/* End XCRemoteSwiftPackageReference section */

ManagedToDos.xctestplan

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

ManagedToDos/Models/ToDo.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@ final class ToDo: NSManagedObject {
1616

1717
var title : String
1818
var isDone : Bool
19-
var priority : Int
19+
var priority : Priority
2020
var created : Date
2121
var due : Date?
2222
var list : ToDoList
2323

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+
2436
convenience init(list : ToDoList,
2537
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)
3042
{
3143
// This is important so that the objects don't end up in different
3244
// contexts.

ManagedToDos/Models/ToDoList.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ import ManagedModels
1414
@Model
1515
final class ToDoList: NSManagedObject {
1616

17-
var title : String
18-
var toDos : Set<ToDo> // currently can't use `[ ToDo ]` here.
19-
17+
var title = ""
18+
var toDos = [ ToDo ]()
19+
2020
convenience init(title: String) {
2121
self.init()
2222
self.title = title
23-
self.toDos = []
2423
}
2524

2625
var hasOverdueItems : Bool { toDos.contains { $0.isOverDue && !$0.isDone } }

ManagedToDos/Preview Content/PreviewData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum PreviewData {
3131
// The insert is not even necessary, done by init
3232
ctx.insert(ToDo(list: list, title: "Apples"))
3333
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))
3535
}
3636
do {
3737
let list = ToDoList(title: "To-Do's")
@@ -41,7 +41,7 @@ enum PreviewData {
4141
ctx.insert(ToDo(list: list, title: "Wash 🚗",
4242
due: Date().advanced(by: 7200)))
4343
ctx.insert(ToDo(list: list, title: "Rebuild SwiftData",
44-
priority: 2,
44+
priority: .low,
4545
due: Date().advanced(by: -7200)))
4646
ctx.insert(ToDo(list: list, title: "Do Groceries"))
4747
}

ManagedToDos/Views/ToDoCell.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ struct ToDoCell: View {
5151

5252
Spacer()
5353

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("‼️") }
5656
}
5757

5858
if let due = toDo.due {
5959
Text("\(due, format: .dateTime)")
6060
.font(.footnote)
61-
.foregroundColor(toDo.isOverDue && toDo.priority > 2
61+
.foregroundColor(toDo.isOverDue && toDo.priority > .low
6262
? .red : nil)
6363
}
6464
}

ManagedToDos/Views/ToDoEditor.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@ struct ToDoEditor: View {
5353

5454
if !toDo.isDone {
5555
Picker("Priority", selection: $toDo.priority) {
56-
ForEach(1...5, id: \.self) { priority in
56+
ForEach(ToDo.Priority.allCases, id: \.self) { priority in
5757
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")
6463
}
6564
}
6665
}

ManagedToDos/Views/ToDoListView.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ struct ToDoListView: View {
3535
_toDos = .init(
3636
filter: NSPredicate(format: "list = %@", toDoList),
3737
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)
4242
],
4343
animation: .default
4444
)
@@ -47,7 +47,7 @@ struct ToDoListView: View {
4747
// MARK: - Actions
4848

4949
private func addItem() {
50-
let toDo = ToDo(list: toDoList, title: "", priority: 3)
50+
let toDo = ToDo(list: toDoList, title: "", priority: .medium)
5151
navigationPath.append(toDo)
5252
try? viewContext.save()
5353
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
[ManagedModels](https://github.com/Data-swift/ManagedModels/),
1010
which adds some SwiftData-like `@Model` support to regular CoreData.
1111

12+
Blog article describing ManagedModels: [`@Model` for CoreData](https://www.alwaysrightinstitute.com/managedmodels/).
13+
1214

1315
### Models
1416

@@ -56,6 +58,7 @@ ManagedModels has no other dependencies.
5658
#### Links
5759

5860
- [ManagedModels](https://github.com/Data-swift/ManagedModels/)
61+
- Blog article: [`@Model` for CoreData](https://www.alwaysrightinstitute.com/managedmodels/).
5962
- Apple:
6063
- [CoreData](https://developer.apple.com/documentation/coredata)
6164
- [SwiftData](https://developer.apple.com/documentation/swiftdata)

0 commit comments

Comments
 (0)