0

I have a class A defined in ObjC and Class B - subclass of A defined in Swift. The implementation is as follows:

Class A

- (id)init {
     return [super init];
}

Class B

init(url: NSURL) {
    super.init()
    let request = NSMutableURLRequest(URL: url)
    request.setValue(valueID, forHTTPHeaderField: "value_ID")
    urlRequest = request
}

convenience init(recoveryURL: NSURL) {
    self.init(url: recoveryURL)
}

required public init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

Class B is initialized as follows (since its loaded from the xib file):

ClassB *b = [[ClassB alloc] initWithNibName:@"ClassA" bundle:nil];

The error is seen on super.init() line inside init(url: NSURL) of class B. I'm trying to use convenience initializers. I would appreciate if someone can point me @ where am I going wrong?

Siddharthan Asokan
  • 4,321
  • 11
  • 44
  • 80
  • 1
    Your initialiser isn't calling the designated initialiser of the superclass - refer to "Initializer delegation for class types" in the Swift book. You will need to pass a nib file to your convenience Initializer or at least have your convenience Initializer specify a nib when it calls the superclass initWithNibName – Paulw11 Feb 02 '16 at 05:51

1 Answers1

-1

Consider putting the following code in viewDidLoad:

let request = NSMutableURLRequest(URL: url)
request.setValue(k_strOfferingIdValueHeader, forHTTPHeaderField: "offering_id")
urlRequest = request

It usually is the cleanest option.

Eppilo
  • 763
  • 6
  • 19