Skip to content

Commit 0fbf332

Browse files
Merge pull request #78 from woocommerce/issue/22-account-storage
Storage Layer: Account Entity
2 parents b38c933 + f253378 commit 0fbf332

File tree

8 files changed

+64
-24
lines changed

8 files changed

+64
-24
lines changed

Storage/Storage.xcodeproj/project.pbxproj

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
B505F6DA20BEEA3200BB1B69 /* Account+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D820BEEA3100BB1B69 /* Account+CoreDataProperties.swift */; };
11+
B505F6DB20BEEA3200BB1B69 /* Account+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D920BEEA3200BB1B69 /* Account+CoreDataClass.swift */; };
12+
B505F6DE20BEEA4F00BB1B69 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6DD20BEEA4F00BB1B69 /* CoreDataManager.swift */; };
13+
B505F6E020BEEA8100BB1B69 /* StorageType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6DF20BEEA8100BB1B69 /* StorageType.swift */; };
1014
B52B0F7920AA287C00477698 /* StorageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52B0F7820AA287C00477698 /* StorageManager.swift */; };
1115
B52B0F7B20AA28A800477698 /* Object.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52B0F7A20AA28A800477698 /* Object.swift */; };
1216
B54CA5A320A4BBA600F38CD1 /* Storage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B54CA59920A4BBA500F38CD1 /* Storage.framework */; };
@@ -21,8 +25,6 @@
2125
B59E11DA20A9D00C004121A4 /* WooCommerce.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = B59E11D820A9D00C004121A4 /* WooCommerce.xcdatamodeld */; };
2226
B59E11DE20A9F1FB004121A4 /* CoreDataManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59E11DD20A9F1FB004121A4 /* CoreDataManagerTests.swift */; };
2327
B59E11E020A9F5E6004121A4 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59E11DF20A9F5E6004121A4 /* Constants.swift */; };
24-
B5C1F2A220AA15630085058E /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C1F2A120AA15630085058E /* Storage.swift */; };
25-
B5EE26C520A624D900468622 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5EE26C420A624D900468622 /* CoreDataManager.swift */; };
2628
/* End PBXBuildFile section */
2729

2830
/* Begin PBXContainerItemProxy section */
@@ -36,6 +38,10 @@
3638
/* End PBXContainerItemProxy section */
3739

3840
/* Begin PBXFileReference section */
41+
B505F6D820BEEA3100BB1B69 /* Account+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Account+CoreDataProperties.swift"; sourceTree = "<group>"; };
42+
B505F6D920BEEA3200BB1B69 /* Account+CoreDataClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Account+CoreDataClass.swift"; sourceTree = "<group>"; };
43+
B505F6DD20BEEA4F00BB1B69 /* CoreDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
44+
B505F6DF20BEEA8100BB1B69 /* StorageType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StorageType.swift; sourceTree = "<group>"; };
3945
B52B0F7820AA287C00477698 /* StorageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageManager.swift; sourceTree = "<group>"; };
4046
B52B0F7A20AA28A800477698 /* Object.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Object.swift; sourceTree = "<group>"; };
4147
B54CA59920A4BBA500F38CD1 /* Storage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Storage.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -53,8 +59,6 @@
5359
B59E11D920A9D00C004121A4 /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
5460
B59E11DD20A9F1FB004121A4 /* CoreDataManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManagerTests.swift; sourceTree = "<group>"; };
5561
B59E11DF20A9F5E6004121A4 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
56-
B5C1F2A120AA15630085058E /* Storage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = "<group>"; };
57-
B5EE26C420A624D900468622 /* CoreDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
5862
/* End PBXFileReference section */
5963

6064
/* Begin PBXFrameworksBuildPhase section */
@@ -77,12 +81,20 @@
7781
/* End PBXFrameworksBuildPhase section */
7882

7983
/* Begin PBXGroup section */
84+
B505F6DC20BEEA4F00BB1B69 /* CoreData */ = {
85+
isa = PBXGroup;
86+
children = (
87+
B505F6DD20BEEA4F00BB1B69 /* CoreDataManager.swift */,
88+
);
89+
path = CoreData;
90+
sourceTree = "<group>";
91+
};
8092
B52B0F7C20AA2D9900477698 /* Protocols */ = {
8193
isa = PBXGroup;
8294
children = (
8395
B52B0F7A20AA28A800477698 /* Object.swift */,
84-
B5C1F2A120AA15630085058E /* Storage.swift */,
8596
B52B0F7820AA287C00477698 /* StorageManager.swift */,
97+
B505F6DF20BEEA8100BB1B69 /* StorageType.swift */,
8698
);
8799
path = Protocols;
88100
sourceTree = "<group>";
@@ -121,7 +133,7 @@
121133
B52B0F7C20AA2D9900477698 /* Protocols */,
122134
B54CA5BE20A4BD9A00F38CD1 /* Extensions */,
123135
B59E11D720A9CFF3004121A4 /* Model */,
124-
B59E11DB20A9F1B9004121A4 /* CoreData */,
136+
B505F6DC20BEEA4F00BB1B69 /* CoreData */,
125137
B54CA59C20A4BBA500F38CD1 /* Storage.h */,
126138
B54CA59D20A4BBA600F38CD1 /* Info.plist */,
127139
);
@@ -170,18 +182,12 @@
170182
isa = PBXGroup;
171183
children = (
172184
B59E11D820A9D00C004121A4 /* WooCommerce.xcdatamodeld */,
185+
B505F6D920BEEA3200BB1B69 /* Account+CoreDataClass.swift */,
186+
B505F6D820BEEA3100BB1B69 /* Account+CoreDataProperties.swift */,
173187
);
174188
path = Model;
175189
sourceTree = "<group>";
176190
};
177-
B59E11DB20A9F1B9004121A4 /* CoreData */ = {
178-
isa = PBXGroup;
179-
children = (
180-
B5EE26C420A624D900468622 /* CoreDataManager.swift */,
181-
);
182-
path = CoreData;
183-
sourceTree = "<group>";
184-
};
185191
B59E11DC20A9F1E6004121A4 /* CoreData */ = {
186192
isa = PBXGroup;
187193
children = (
@@ -301,13 +307,15 @@
301307
buildActionMask = 2147483647;
302308
files = (
303309
B54CA5BB20A4BD2800F38CD1 /* NSManagedObject+Object.swift in Sources */,
310+
B505F6DB20BEEA3200BB1B69 /* Account+CoreDataClass.swift in Sources */,
304311
B54CA5BD20A4BD3B00F38CD1 /* NSManagedObjectContext+Storage.swift in Sources */,
305312
B59E11DA20A9D00C004121A4 /* WooCommerce.xcdatamodeld in Sources */,
306313
B52B0F7920AA287C00477698 /* StorageManager.swift in Sources */,
314+
B505F6E020BEEA8100BB1B69 /* StorageType.swift in Sources */,
307315
B54CA5C920A4C17800F38CD1 /* NSObject+Storage.swift in Sources */,
308-
B5EE26C520A624D900468622 /* CoreDataManager.swift in Sources */,
316+
B505F6DA20BEEA3200BB1B69 /* Account+CoreDataProperties.swift in Sources */,
309317
B52B0F7B20AA28A800477698 /* Object.swift in Sources */,
310-
B5C1F2A220AA15630085058E /* Storage.swift in Sources */,
318+
B505F6DE20BEEA4F00BB1B69 /* CoreDataManager.swift in Sources */,
311319
);
312320
runOnlyForDeploymentPostprocessing = 0;
313321
};

Storage/Storage/CoreData/CoreDataManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class CoreDataManager: StorageManager {
2424

2525
/// Returns the Storage associated with the View Thread.
2626
///
27-
public var viewStorage: Storage {
27+
public var viewStorage: StorageType {
2828
return persistentContainer.viewContext
2929
}
3030

@@ -46,9 +46,9 @@ public class CoreDataManager: StorageManager {
4646

4747
/// Performs the received closure in Background. Note that you should use the received Storage instance (BG friendly!).
4848
///
49-
public func performBackgroundTask(_ closure: @escaping (Storage) -> Void) {
49+
public func performBackgroundTask(_ closure: @escaping (StorageType) -> Void) {
5050
persistentContainer.performBackgroundTask { context in
51-
closure(context as Storage)
51+
closure(context as StorageType)
5252
}
5353
}
5454
}

Storage/Storage/Extensions/NSManagedObjectContext+Storage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CoreData
44

55
/// NSManagedObjectContext Storage Conformance
66
///
7-
extension NSManagedObjectContext: Storage {
7+
extension NSManagedObjectContext: StorageType {
88

99
/// Returns all of the entities that match with a given predicate.
1010
///
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
import CoreData
3+
4+
@objc(Account)
5+
public class Account: NSManagedObject {
6+
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Foundation
2+
import CoreData
3+
4+
5+
extension Account {
6+
7+
@nonobjc public class func fetchRequest() -> NSFetchRequest<Account> {
8+
return NSFetchRequest<Account>(entityName: "Account")
9+
}
10+
11+
@NSManaged public var displayName: String?
12+
@NSManaged public var email: String?
13+
@NSManaged public var gravatarUrl: String?
14+
@NSManaged public var username: String?
15+
@NSManaged public var userID: Int64
16+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
22
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14133" systemVersion="17E202" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
3-
<elements/>
3+
<entity name="Account" representedClassName="Account" syncable="YES">
4+
<attribute name="displayName" optional="YES" attributeType="String" syncable="YES"/>
5+
<attribute name="email" optional="YES" attributeType="String" syncable="YES"/>
6+
<attribute name="gravatarUrl" optional="YES" attributeType="String" syncable="YES"/>
7+
<attribute name="userID" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
8+
<attribute name="username" attributeType="String" syncable="YES"/>
9+
</entity>
10+
<elements>
11+
<element name="Account" positionX="-63" positionY="-18" width="128" height="120"/>
12+
</elements>
413
</model>

Storage/Storage/Protocols/StorageManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ public protocol StorageManager {
77

88
/// Returns the `Storage` associated to the main thread.
99
///
10-
var viewStorage: Storage { get }
10+
var viewStorage: StorageType { get }
1111

1212
/// Performs a task in Background: a special `Storage` instance will be provided (which is expected to be used within the closure!).
1313
/// Note that you must NEVER use the viewStorage within the backgroundClosure.
1414
///
15-
func performBackgroundTask(_ closure: @escaping (Storage) -> Void)
15+
func performBackgroundTask(_ closure: @escaping (StorageType) -> Void)
1616
}

Storage/Storage/Protocols/Storage.swift renamed to Storage/Storage/Protocols/StorageType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33

44
/// Defines all of the methods made available by the Storage.
55
///
6-
public protocol Storage {
6+
public protocol StorageType {
77

88
/// Returns all of the available objects of a given Type, matching the specified Predicate (and sorted with a given collection of
99
/// SortDescriptors).

0 commit comments

Comments
 (0)