[swift-users] Unavailable initializers in -Swift.h

Svein Halvor Halvorsen svein.h at lvor.halvorsen.cc
Wed Jun 8 08:12:18 CDT 2016


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;


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

However, If I declare a Swift class like this:

class SomeClass: NSObject {

    init(dependency: Dependency) {




The generated header file will look like this:

@interface SomeClass : NSObject

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


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

Svein Halvor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160608/e4ac2186/attachment.html>

More information about the swift-users mailing list