Skip to content

Commit c43a530

Browse files
committed
StorageType+Extensions: New Tool
1 parent 19b4770 commit c43a530

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

Storage/Storage.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
7028A41485A08AC748206184 /* Pods_Storage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF3D3B298350F68191CD1DAD /* Pods_Storage.framework */; };
1212
B505254920EE6080008090F5 /* Site+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505254720EE607F008090F5 /* Site+CoreDataProperties.swift */; };
1313
B505254A20EE6080008090F5 /* Site+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505254820EE6080008090F5 /* Site+CoreDataClass.swift */; };
14+
B505255420EE6914008090F5 /* StorageType+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505255320EE6914008090F5 /* StorageType+Extensions.swift */; };
1415
B505F6DA20BEEA3200BB1B69 /* Account+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D820BEEA3100BB1B69 /* Account+CoreDataProperties.swift */; };
1516
B505F6DB20BEEA3200BB1B69 /* Account+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D920BEEA3200BB1B69 /* Account+CoreDataClass.swift */; };
1617
B505F6DE20BEEA4F00BB1B69 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6DD20BEEA4F00BB1B69 /* CoreDataManager.swift */; };
@@ -49,6 +50,7 @@
4950
A3821B262583F14863740A37 /* Pods-Storage.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Storage.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Storage/Pods-Storage.debug.xcconfig"; sourceTree = "<group>"; };
5051
B505254720EE607F008090F5 /* Site+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Site+CoreDataProperties.swift"; path = "/Users/lantean/Developer/Automattic/woocommerce-ios/Storage/Storage/Model/Site+CoreDataProperties.swift"; sourceTree = "<absolute>"; };
5152
B505254820EE6080008090F5 /* Site+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Site+CoreDataClass.swift"; path = "/Users/lantean/Developer/Automattic/woocommerce-ios/Storage/Storage/Model/Site+CoreDataClass.swift"; sourceTree = "<absolute>"; };
53+
B505255320EE6914008090F5 /* StorageType+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StorageType+Extensions.swift"; sourceTree = "<group>"; };
5254
B505F6D820BEEA3100BB1B69 /* Account+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Account+CoreDataProperties.swift"; sourceTree = "<group>"; };
5355
B505F6D920BEEA3200BB1B69 /* Account+CoreDataClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Account+CoreDataClass.swift"; sourceTree = "<group>"; };
5456
B505F6DD20BEEA4F00BB1B69 /* CoreDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
@@ -107,6 +109,14 @@
107109
name = Pods;
108110
sourceTree = "<group>";
109111
};
112+
B505255520EE694F008090F5 /* Tools */ = {
113+
isa = PBXGroup;
114+
children = (
115+
B505255320EE6914008090F5 /* StorageType+Extensions.swift */,
116+
);
117+
path = Tools;
118+
sourceTree = "<group>";
119+
};
110120
B505F6DC20BEEA4F00BB1B69 /* CoreData */ = {
111121
isa = PBXGroup;
112122
children = (
@@ -160,6 +170,7 @@
160170
B52B0F7C20AA2D9900477698 /* Protocols */,
161171
B54CA5BE20A4BD9A00F38CD1 /* Extensions */,
162172
B59E11D720A9CFF3004121A4 /* Model */,
173+
B505255520EE694F008090F5 /* Tools */,
163174
B505F6DC20BEEA4F00BB1B69 /* CoreData */,
164175
B54CA59C20A4BBA500F38CD1 /* Storage.h */,
165176
B54CA59D20A4BBA600F38CD1 /* Info.plist */,
@@ -408,6 +419,7 @@
408419
B505F6E020BEEA8100BB1B69 /* StorageType.swift in Sources */,
409420
B54CA5C920A4C17800F38CD1 /* NSObject+Storage.swift in Sources */,
410421
B505F6DA20BEEA3200BB1B69 /* Account+CoreDataProperties.swift in Sources */,
422+
B505255420EE6914008090F5 /* StorageType+Extensions.swift in Sources */,
411423
B52B0F7B20AA28A800477698 /* Object.swift in Sources */,
412424
B505F6DE20BEEA4F00BB1B69 /* CoreDataManager.swift in Sources */,
413425
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
3+
4+
// MARK: - StorageType DataModel Specific Extensions
5+
//
6+
public extension StorageType {
7+
8+
/// Retrieves the Stored Account.
9+
///
10+
public func loadAccount(userId: Int) -> Account? {
11+
let predicate = NSPredicate(format: "userID = %ld", userId)
12+
return firstObject(ofType: Account.self, matching: predicate)
13+
}
14+
15+
/// Retrieves the Stored Site.
16+
///
17+
public func loadSite(siteID: Int) -> Site? {
18+
let predicate = NSPredicate(format: "siteID = %ld", siteID)
19+
return firstObject(ofType: Site.self, matching: predicate)
20+
}
21+
}

Yosemite/Yosemite/Stores/AccountStore.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private extension AccountStore {
7272

7373
// MARK: - Persistance
7474
//
75-
private extension AccountStore {
75+
extension AccountStore {
7676

7777
/// Updates (OR Inserts) the specified ReadOnly Account Entity into the Storage Layer.
7878
///
@@ -101,23 +101,3 @@ private extension AccountStore {
101101
storage.saveIfNeeded()
102102
}
103103
}
104-
105-
106-
// MARK: - StorageType (AccountStore) private methods.
107-
//
108-
private extension StorageType {
109-
110-
/// Retrieves the Stored Account.
111-
///
112-
func loadAccount(userId: Int) -> Storage.Account? {
113-
let predicate = NSPredicate(format: "userID = %ld", userId)
114-
return firstObject(ofType: Storage.Account.self, matching: predicate)
115-
}
116-
117-
/// Retrieves the Stored Site.
118-
///
119-
func loadSite(siteID: Int) -> Storage.Site? {
120-
let predicate = NSPredicate(format: "siteID = %ld", siteID)
121-
return firstObject(ofType: Storage.Site.self, matching: predicate)
122-
}
123-
}

0 commit comments

Comments
 (0)