Expose a Swift initializer as an Objective-C factory constructor

I'm creating a compatibility layer for a new Swift implementation of a legacy Objective-C library. The Objective-C library has a class whose only constructor is a factory constructor:

Code Block
+ (instancetype)fooWithBar:(NSString *)bar;


I know that when bridging from Objective-C to Swift the factory constructors are turned into convenience initializers. But I'm trying to do the reverse, that is create a factory constructor for a Swift class. The convenience initializer gets turned into something along the lines of:

Code Block
- (instancetype)initWithBar:(NSString *)bar;


So my approach is to create a static method in Swift that returns an instance of Self:

Code Block
@objc static func foo(bar: String) -> Self


This gets exposed correctly, but I'm a little uneasy since it's clearly asymmetric with the Objective-C -> Swift bridging, and also it returns an owned reference, where the Objective-C convention would be that a factory constructor returns an autoreleased object.

Long story short, is the static func the way to go, and am I creating a memory leak here? (and if so, how should I fix it?)

is the static func the way to go

It seems to be the only way to go, if you want an ObjC class method exposed.

am I creating a memory leak here?

Not sure, but it is expected not to make a memory leak. If that can be a cause of leak, any Swift methods returning ObjC object would cause leaks.
Have you ever found any leaks with your static method using Instruments?
Expose a Swift initializer as an Objective-C factory constructor
 
 
Q