diff --git a/Sources/WordPressData/Objective-C/include/CoreDataStack.h b/Sources/WordPressData/Objective-C/include/CoreDataStack.h deleted file mode 100644 index 69c79f3a95ab..000000000000 --- a/Sources/WordPressData/Objective-C/include/CoreDataStack.h +++ /dev/null @@ -1,42 +0,0 @@ -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -@protocol CoreDataStack - -@property (nonatomic, readonly, strong) NSManagedObjectContext *mainContext; - -- (NSManagedObjectContext *const)newDerivedContext DEPRECATED_MSG_ATTRIBUTE("Use `performAndSave` instead"); - -- (void)saveContextAndWait:(NSManagedObjectContext *)context; - -- (void)saveContext:(NSManagedObjectContext *)context; - -- (void)saveContext:(NSManagedObjectContext *)context -withCompletionBlock:(void (^ _Nullable)(void))completionBlock - onQueue:(dispatch_queue_t)queue NS_SWIFT_NAME(save(_:completion:on:)); - -/// Execute the given block with a background context and save the changes. -/// -/// This function _blocks_ its running thread. The changed made by the `aBlock` argument are saved before this -/// function returns. -/// -/// - Parameter aBlock: A block which uses the given `NSManagedObjectContext` to make Core Data model changes. -- (void)performAndSaveUsingBlock:(void (^)(NSManagedObjectContext *context))aBlock; - -/// Execute the given block with a background context and save the changes _if the block does not throw an error_. -/// -/// This function _does not block_ its running thread. The `aBlock` argument is executed in the background. The -/// `completion` block is called after the Core Data model changes are saved. -/// -/// - Parameters: -/// - aBlock: A block which uses the given `NSManagedObjectContext` to make Core Data model changes. -/// - completion: A block which is called after the changes made by the `block` are saved. -/// - queue: A queue on which to execute the `completion` block. -- (void)performAndSaveUsingBlock:(void (^)(NSManagedObjectContext *context))aBlock - completion:(void (^ _Nullable)(void))completion onQueue:(dispatch_queue_t)queue; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/WordPressData/Swift/CoreDataStack.swift b/Sources/WordPressData/Swift/CoreDataStack.swift new file mode 100644 index 000000000000..050deca37c62 --- /dev/null +++ b/Sources/WordPressData/Swift/CoreDataStack.swift @@ -0,0 +1,23 @@ +import CoreData + +@objc public protocol CoreDataStack { + + var mainContext: NSManagedObjectContext { get } + + @available(*, deprecated, message: "Use `performAndSave` instead") + func newDerivedContext() -> NSManagedObjectContext + + func saveContextAndWait(_ context: NSManagedObjectContext) + + @objc(saveContext:) + func save(_ context: NSManagedObjectContext) + + @objc(saveContext:withCompletionBlock:onQueue:) + func save(_ context: NSManagedObjectContext, completion: (() -> Void)?, on queue: DispatchQueue) + + @objc(performAndSaveUsingBlock:) + func performAndSave(_ block: @escaping (NSManagedObjectContext) -> Void) + + @objc(performAndSaveUsingBlock:completion:onQueue:) + func performAndSave(_ block: @escaping (NSManagedObjectContext) -> Void, completion: (() -> Void)?, on queue: DispatchQueue) +} diff --git a/Sources/WordPressData/WordPressData.h b/Sources/WordPressData/WordPressData.h index 632ba5fc501b..7e47e5883fa7 100644 --- a/Sources/WordPressData/WordPressData.h +++ b/Sources/WordPressData/WordPressData.h @@ -9,7 +9,6 @@ FOUNDATION_EXPORT const unsigned char WordPressDataVersionString[]; // Note: Some of these might not need to be public, but it was simpler to extract to WordPressData by making everything public. // As we'll hopefully soon rewrite these in Swift, we can implement proper access level then. #import -#import #import FOUNDATION_EXTERN void SetCocoaLumberjackObjCLogLevel(NSUInteger ddLogLevelRawValue); diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index a88d0fe5029f..19ee85fe6f98 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -1168,7 +1168,6 @@ isa = PBXFileSystemSynchronizedBuildFileExceptionSet; publicHeaders = ( "Objective-C/include/Blog.h", - "Objective-C/include/CoreDataStack.h", "Objective-C/include/PostHelper.h", WordPressData.h, );