Hi,

In Objective-C, I've often attributed initializer from super classes as
unavailable. Like this;

@class Dependency;

@interface SomeClass : NSObject

- (nullable instancetype)init __unavailable;

- (nonnull instancetype)initWithDependency:(nonnull Dependency *)dependency;

@end

This makes the compiler complain if I try to instantiate [[SomeClass alloc]
init];

However, If I declare a Swift class like this:

class SomeClass: NSObject {

    init(dependency: Dependency) {

        super.init()

    }

}

The generated header file will look like this:


@interface SomeClass : NSObject

- (nonnull instancetype)initWithDependency:(Dependency * _Nonnull)dependency
OBJC_DESIGNATED_INITIALIZER;

@end

If I try to use init, it will be a run time error, and not a compile time
error.
It there any way I can make Swift create the desired objc header file?


Svein Halvor
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to