Skip to content

Commit 9817937

Browse files
committed
Squashed commit of the following:
commit c8b21b22c078145451508664383a54ea3e9cb56b Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Wed Feb 3 09:00:12 2021 -0600 Remove CI build and codecov status badges from readme. commit de7e662 Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 12:20:51 2021 -0600 WIP commit 7f9a304 Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 12:16:42 2021 -0600 WIP commit 61ce65e Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 11:53:20 2021 -0600 WIP commit 5786bce Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 11:50:07 2021 -0600 WIP commit 4307ccf Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 11:42:54 2021 -0600 WIP commit dfe87a8 Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 11:36:34 2021 -0600 WIP commit 1334283 Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 11:28:07 2021 -0600 Upload to codecov commit 2fed974 Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 11:18:34 2021 -0600 WIP commit 2e459eb Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 11:03:25 2021 -0600 Tests work. Troubleshoot codecov commit 710909e Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 10:48:51 2021 -0600 Manually build NSManagedObjectModel commit 2a2b7b3 Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 09:00:40 2021 -0600 Update travis xcode version commit b35702c Author: Andrew Roan <roanutil@users.noreply.github.com> Date: Mon Feb 1 08:53:56 2021 -0600 Add travis ci and codecov
1 parent 4d42afb commit 9817937

6 files changed

Lines changed: 86 additions & 43 deletions

File tree

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: swift
2+
os: osx
3+
osx_image: xcode12u
4+
script:
5+
- swift build
6+
- swift test --enable-code-coverage
7+
after_success:
8+
- brew install llvm
9+
- echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc
10+
- ./codecov.sh
11+
- bash <(curl -s https://codecov.io/bash)

Package.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ let package = Package(
2929
dependencies: []),
3030
.testTarget(
3131
name: "CoreDataRepositoryTests",
32-
dependencies: ["CoreDataRepository"]),
32+
dependencies: ["CoreDataRepository"],
33+
resources: [
34+
.process("Model.xcdatamodeld")
35+
]
36+
),
3337
]
3438
)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# CoreDataRepository
2+
[![Build Status](https://travis-ci.com/roanutil/CoreDataRepository.svg?branch=main)](https://travis-ci.com/roanutil/CoreDataRepository) [![codecov](https://codecov.io/gh/roanutil/CoreDataRepository/branch/main/graph/badge.svg?token=WRO4CXYWRG)](https://codecov.io/gh/roanutil/CoreDataRepository)
23

34
CoreDataRepository is a reactive library (Combine) for using CoreData on a background queue. It features endpoints for CRUD, batch, fetch multiple, and aggregate operations. Also, it offers a stream like subscription function for wrapping a fetch multiple call that will send updates that match the fetch request.
45

Tests/CoreDataRepositoryTests/CoreDataStack.swift

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import CoreData
99

1010
class CoreDataStack: NSObject {
1111
private static let model: NSManagedObjectModel = {
12-
guard let modelURL = Bundle.module.url(forResource: "Model", withExtension: "momd") else {
12+
// Manually build model entities. Having trouble with the package loading the model from bundle.
13+
/*guard let modelURL = Bundle.module.url(forResource: "Model", withExtension: "momd") else {
1314
fatalError("Failed to create bundle URL for CoreData model.")
1415
}
1516

1617
guard let model = NSManagedObjectModel(contentsOf: modelURL) else {
1718
fatalError("Failed to init CoreData model from URL.")
18-
}
19+
}*/
20+
let model = NSManagedObjectModel()
21+
model.entities = [MovieDescription]
1922
return model
2023
}()
2124

@@ -34,4 +37,49 @@ class CoreDataStack: NSObject {
3437
}
3538
return container
3639
}
40+
41+
// Manually build model entities. Having trouble with the package loading the model from bundle.
42+
static private var MovieDescription: NSEntityDescription {
43+
let desc = NSEntityDescription()
44+
desc.name = "RepoMovie"
45+
desc.managedObjectClassName = NSStringFromClass(RepoMovie.self)
46+
desc.properties = [
47+
movieIDDescription,
48+
movieTitleDescription,
49+
movieReleaseDateDescription,
50+
movieBoxOfficeDescription
51+
]
52+
desc.uniquenessConstraints = [["id"]]
53+
return desc
54+
}
55+
56+
static private var movieIDDescription: NSAttributeDescription {
57+
let desc = NSAttributeDescription()
58+
desc.name = "id"
59+
desc.attributeType = .UUIDAttributeType
60+
return desc
61+
}
62+
63+
static private var movieTitleDescription: NSAttributeDescription {
64+
let desc = NSAttributeDescription()
65+
desc.name = "title"
66+
desc.attributeType = .stringAttributeType
67+
desc.defaultValue = ""
68+
return desc
69+
}
70+
71+
static private var movieReleaseDateDescription: NSAttributeDescription {
72+
let desc = NSAttributeDescription()
73+
desc.name = "releaseDate"
74+
desc.attributeType = .dateAttributeType
75+
return desc
76+
}
77+
78+
static private var movieBoxOfficeDescription: NSAttributeDescription {
79+
let desc = NSAttributeDescription()
80+
desc.name = "boxOffice"
81+
desc.attributeType = .decimalAttributeType
82+
desc.defaultValue = 0
83+
return desc
84+
}
3785
}

Tests/CoreDataRepositoryTests/Model.xcdatamodeld/Model.xcdatamodel/contents

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
22
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20C69" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
3-
<entity name="RepoMovie" representedClassName="RepoMovie" syncable="YES" codeGenerationType="category">
3+
<entity name="RepoMovie" representedClassName="RepoMovie" syncable="YES">
44
<attribute name="boxOffice" attributeType="Decimal" defaultValueString="0.0"/>
55
<attribute name="id" attributeType="UUID" usesScalarValueType="NO"/>
66
<attribute name="releaseDate" attributeType="Date" usesScalarValueType="NO"/>

Tests/CoreDataRepositoryTests/Movie.swift

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import CoreData
99
@testable import CoreDataRepository
1010

11-
public struct Movie: Identifiable, Equatable {
11+
public struct Movie {
1212
public let id: UUID
1313
public var title: String = ""
1414
public var releaseDate: Date
@@ -27,50 +27,24 @@ extension Movie: UnmanagedModel {
2727
}
2828
}
2929

30-
/*@objc(RepoMovie)
31-
final class RepoMovie: NSManagedObject, Identifiable {
32-
@NSManaged var id: UUID
33-
@NSManaged var title: String
34-
@NSManaged var releaseDate: Date
35-
@NSManaged var boxOffice: NSDecimalNumber
36-
}
37-
38-
extension RepoMovie: RepositoryManagedModel {
39-
var asUnmanaged: Movie {
40-
return Movie(
41-
id: id,
42-
title: title,
43-
releaseDate: releaseDate,
44-
boxOffice: boxOffice as Decimal,
45-
objectID: objectID
46-
)
47-
}
48-
49-
func update(from unmanaged: Movie) {
50-
self.id = unmanaged.id
51-
self.title = unmanaged.title
52-
self.releaseDate = unmanaged.releaseDate
53-
self.boxOffice = unmanaged.boxOffice as NSDecimalNumber
54-
}
55-
56-
static func fetchRequest() -> NSFetchRequest<RepoMovie> {
57-
NSFetchRequest<RepoMovie>(entityName: "RepoMovie")
58-
}
59-
}
60-
*/
61-
62-
import Foundation
63-
import CoreData
64-
6530
@objc(RepoMovie)
66-
public class RepoMovie: NSManagedObject {
67-
31+
public final class RepoMovie: NSManagedObject {
32+
@NSManaged var id: UUID?
33+
@NSManaged var title: String?
34+
@NSManaged var releaseDate: Date?
35+
@NSManaged var boxOffice: NSDecimalNumber?
6836
}
6937

7038
extension RepoMovie: RepositoryManagedModel {
7139
public typealias Unmanaged = Movie
7240
public var asUnmanaged: Movie {
73-
return Movie(id: self.id ?? UUID(), title: self.title ?? "", releaseDate: self.releaseDate ?? Date(), boxOffice: (self.boxOffice ?? 0) as Decimal, objectID: self.objectID)
41+
return Movie(
42+
id: self.id ?? UUID(),
43+
title: self.title ?? "",
44+
releaseDate: self.releaseDate ?? Date(),
45+
boxOffice: (self.boxOffice ?? 0) as Decimal,
46+
objectID: self.objectID
47+
)
7448
}
7549

7650
public func update(from unmanaged: Movie) {
@@ -79,4 +53,9 @@ extension RepoMovie: RepositoryManagedModel {
7953
self.releaseDate = unmanaged.releaseDate
8054
self.boxOffice = NSDecimalNumber(decimal: unmanaged.boxOffice)
8155
}
56+
57+
static func fetchRequest() -> NSFetchRequest<RepoMovie> {
58+
let request = NSFetchRequest<RepoMovie>(entityName: "RepoMovie")
59+
return request
60+
}
8261
}

0 commit comments

Comments
 (0)