-
Type:
Improvement
-
Status: Resolved
-
Priority:
Medium
-
Resolution: Done
-
Component/s: Compiler
-
Labels:None
In Swift, the following is permitted:
protocol Foo {
static func makeFoo() -> Self
}
But if the protocol is marked as @objc, it generates the warning "Method cannot be a member of an @objc protocol because its result type cannot be represented in Objective-C"
However, adding Self as a return type to a protocol method doesn't usually treat Self as an associatedType requirement, so it's not clear why a protocol method returning Self can't be represented in Objective-C.
The equivalent Objective-C code is permitted and works as you'd expect:
@protocol Foo + (instancetype)makeFoo; @end @interface Bar: NSObject<Foo> @end @implementation Bar + (instancetype)makeFoo { return [[self alloc] init]; } @end