Skip to content

Commit 7150b07

Browse files
committed
Replace all ContextManager sharedInstance() usages with shared
Apart from being more Swift-y, this will also allow us to differentiate between a shared instance for the Objective-C layer (`CoreDataStack`) and one for the Swift layer (`CoreDataStackSwift`). This differentiation will be valuable if/when we'll replace `ContextManager` references with `CoreDataStack`/`CoreDataStackSwift` so that WordPressDataObjC can refer to the functionality without knowing about `ContextManager`, which is defined in the Swift WordPressData layer.
1 parent b8f184b commit 7150b07

File tree

87 files changed

+133
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+133
-133
lines changed

WordPress/Classes/Models/Blog/Blog+HomepageSettings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ extension Blog {
106106
guard let pageID = homepageType == .page ? homepagePageID
107107
: homepageType == .posts ? homepagePostsPageID
108108
: nil else { return nil }
109-
let context = ContextManager.sharedInstance().mainContext
109+
let context = ContextManager.shared.mainContext
110110
return lookupPost(withID: Int64(pageID), in: context) as? Page
111111
}
112112
}

WordPress/Classes/Models/Notifications/Actions/NotificationAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DefaultNotificationActionCommand: FormattableContentActionCommand {
1515
}
1616

1717
private(set) lazy var mainContext: NSManagedObjectContext? = {
18-
return ContextManager.sharedInstance().mainContext
18+
return ContextManager.shared.mainContext
1919
}()
2020

2121
private(set) lazy var actionsService: NotificationActionsService? = {

WordPress/Classes/Services/AccountSettingsService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AccountSettingsService {
6464
self.init(userID: userID, remote: remote)
6565
}
6666

67-
init(userID: Int, remote: AccountSettingsRemoteInterface, coreDataStack: CoreDataStackSwift = ContextManager.sharedInstance()) {
67+
init(userID: Int, remote: AccountSettingsRemoteInterface, coreDataStack: CoreDataStackSwift = ContextManager.shared) {
6868
self.userID = userID
6969
self.remote = remote
7070
self.coreDataStack = coreDataStack

WordPress/Classes/Services/JetpackNotificationMigrationService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer
2626
}
2727

2828
private lazy var notificationSettingsService: NotificationSettingsService? = {
29-
NotificationSettingsService(coreDataStack: ContextManager.sharedInstance())
29+
NotificationSettingsService(coreDataStack: ContextManager.shared)
3030
}()
3131

3232
private lazy var bloggingRemindersScheduler: BloggingRemindersScheduler? = {

WordPress/Classes/Services/NotificationSyncMediator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ final class NotificationSyncMediator: NotificationSyncMediatorProtocol {
7979
/// Designed Initializer
8080
///
8181
convenience init?() {
82-
let manager = ContextManager.sharedInstance()
82+
let manager = ContextManager.shared
8383

8484
guard let dotcomAPI = try? WPAccount.lookupDefaultWordPressComAccount(in: manager.mainContext)?.wordPressComRestApi else {
8585
return nil

WordPress/Classes/Services/PostCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class PostCoordinator: NSObject {
6161

6262
init(mediaCoordinator: MediaCoordinator? = nil,
6363
actionDispatcherFacade: ActionDispatcherFacade = ActionDispatcherFacade(),
64-
coreDataStack: CoreDataStackSwift = ContextManager.sharedInstance()) {
64+
coreDataStack: CoreDataStackSwift = ContextManager.shared) {
6565
self.coreDataStack = coreDataStack
6666
self.mediaCoordinator = mediaCoordinator ?? MediaCoordinator.shared
6767
self.actionDispatcherFacade = actionDispatcherFacade

WordPress/Classes/Services/PostService+Revisions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension PostService {
2323
for: postId.intValue,
2424
with: blogId.intValue
2525
)
26-
ContextManager.sharedInstance().save(self.managedObjectContext, completion: success, on: .main)
26+
ContextManager.shared.save(self.managedObjectContext, completion: success, on: .main)
2727
}
2828
}, failure: failure)
2929
}

WordPress/Classes/Services/PostService+UnattachedMedia.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension PostService {
1515

1616
let mediaService = MediaService(managedObjectContext: self.managedObjectContext)
1717
mediaService.updateMedia(mediaToUpdate, fieldsToUpdate: ["postID"], overallSuccess: {
18-
ContextManager.sharedInstance().save(self.managedObjectContext)
18+
ContextManager.shared.save(self.managedObjectContext)
1919
success()
2020
}) { error in
2121
failure(error)

WordPress/Classes/Services/WordPressComSyncService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class WordPressComSyncService {
6565
/// - onFailure: Failure block
6666
///
6767
func syncOrAssociateBlogs(account: WPAccount, isJetpackLogin: Bool, onSuccess: @escaping (WPAccount) -> Void, onFailure: @escaping (Error) -> Void) {
68-
let accountService = AccountService(coreDataStack: ContextManager.sharedInstance())
68+
let accountService = AccountService(coreDataStack: ContextManager.shared)
6969

7070
let onFailureInternal = { (error: Error) in
7171
/// At this point the user is authed and there is a valid account in core data. Make a note of the error and just dismiss

WordPress/Classes/Stores/ActivityStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ActivityStore: QueryStore<ActivityStoreState, ActivityQuery> {
100100
activityServiceRemote: ActivityServiceRemote? = nil,
101101
backupService: JetpackBackupService? = nil) {
102102
self.activityServiceRemote = activityServiceRemote
103-
self.backupService = backupService ?? JetpackBackupService(coreDataStack: ContextManager.sharedInstance())
103+
self.backupService = backupService ?? JetpackBackupService(coreDataStack: ContextManager.shared)
104104
super.init(initialState: ActivityStoreState(), dispatcher: dispatcher)
105105
}
106106

0 commit comments

Comments
 (0)