How to expose pure Swift classes to Objective-C correctly?

Consider this:

MyFile.swift:

@objc class SomeGuy {
}


MyClass.m:

#import "MyApp-Swift.h"
@interface SomeClass
@end
@implementation SomeClass
- (void)someMethod {
SomeGuy *someGuy = [[SomeGuy alloc] init];
}
@end


In other words: have a pure Swift class annotated with @objc so it’s visible to Objective-C code. In Objective-C code, try to instantiate that class.

If you were to run the above, you’d get compiler error: “no known class method for selector 'alloc'”


One way to fix this would be to make SomeGuy inherit from NSObject. But I don’t want to do that, since I feel it adds too much cruft, the class isn’t really inheriting from NSObject by its nature, it is a pure swift class.


Another way to fix: over on the Objective-C side, have a category:

@interface SomeGuy (Dummy)
+ (instancetype)alloc;
@end


This works and feels less weird, but still weird. It feels that the Swift-to-ObjC should autogenerate the alloc declaration for me in this case, since if I just add this category interface, everything works correctly.


Have I missed something? Or am I thinking about this wrong? What’s the best practice to expose a Swift class to Objective-C?

How to expose pure Swift classes to Objective-C correctly?
 
 
Q