The code I’m working on now (inherited from another team) has a persistence layer based on CoreData.
One of the entities is named “Notification”, and it represents messages periodically polled by the client app from the back end (unrelated to APS); the corresponding NSManagedObject subclass is defined the following way:
import Foundation
import CoreData
@objc(Notification) public class Notification: NSManagedObject {
// etc...
Needless to say, this class name shadows the homonymous Foundation type (counterpart to NSNotification on the Objective-C side). The app does not use the NotificationCenter machinery, so it wasn't a problem until now.
Now I need to introduce notifications for some of my classes to observe certain app-level events, and I don’t want to have to disambiguate each and every time, e.g.
let notification = Foundation.Notification.Name(...
I am aware that I cannot change the class names of my CoreData entities without breaking compatibility, but I thought that the @objc(Notification) would let me change the Swift class name; for example:
@objc(Notification) public class AppNotification: NSManagedObject {
// ^ This stays the same ^ This changes
...after all, CoreData is an Objective-C API. It makes sense that, if I have to explicitly specify the Objective-C bridged class name, perhaps I can get away with a Swift class name that is different from the model.
But no, my app crashes if I make the change above.
Is there a way around this, or am I stuck with the horrible decision (and lack of foresight) of the original author?


typealiasforFoundation.Notification? - Sweeper@objc(Notification)doesn't interfere with theFoundation.Notification- the reference Obj-C type isNSNotification. Anyway, you can change the class name (see my answer) and it shouldn't crash. If it crashes, there're some other problems in your code base which were hidden till now (like someone was usingclassNameto get entity name, ...). Or it can be the code generation issue, old derived data, ... Include the stack trace so we can see what's going on. - zrzka