I created an extension for Notification.Name
as below :
public extension Notification.Name {
public static let blahblahblah = Notification.Name(rawValue: "blahblahblah")
}
Now I want to use this extension in Objective-C, but it's not accessible even if its public.
Can you tell me how to access and use this swift extension in Objective-C and Swift both?
previously I was using constant values in Objective-C, but now for upgrading my code, I wanna use this extension.
My extension in swift file
extension Notification.Name {
static let purchaseDidFinish = Notification.Name("purchaseDidFinish")
}
@objc extension NSNotification {
public static let purchaseDidFinish = Notification.Name.purchaseDidFinish
}
// OBJECTIVE-C
#import YourProjectName-Swift.h
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(purchaseDidFinish) name:NSNotification.purchaseDidFinish object:nil];
// SWIFT
NotificationCenter.default.addObserver(self, selector: #selector(purchaseDidFinish), name: .purchaseDidFinish, object: nil)
@objc func purchaseDidFinish(notification: Notification) {
print("purchaseDidFinish")
}
@leanne's answer was super helpful