0

I can't seem to extend a class from cocoapod ra1028/Former in my application with the right initializers from the parent class. Why is this?

See below situation divided into the code from the pod and my application code (ExtendedFormLabelHeaderView class)

// ra1028/Former cocaopod class signatures

public protocol FormableView: class {}
public protocol LabelFormableView: FormableView {}

open class FormHeaderFooterView: UITableViewHeaderFooterView {
    required public init?(coder aDecoder: NSCoder) {     
        super.init(coder: aDecoder)
    }
    override public init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
    }
}

open class FormLabelHeaderView: FormHeaderFooterView, LabelFormableView {
    required public init?(coder aDecoder: NSCoder) { 
        super.init(coder: aDecoder)
    }
    override public init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
    }
}

// my app code

open class ExtendedFormLabelHeaderView: FormLabelHeaderView {
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    override public init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
    }
}

Running above code in the playground works.

But running it as setup in my workspace (coming from Swift 2.2, converted to Swift 3) it will first complain about ExtendedFormLabelHeaderView's override init(reuseIdentifier: String?) initializer not being public (most likely because it cannot find the initializer it needs to override?) and then I end up with these error messages:

  • Initializer does not override a designated initializer from its superclass.
  • Argument labels '(reuseIdentifier:)' do not match any available overloads

Some other things to note:

  • It worked back in 2.2
  • I updated Former to the latest Swift 3.0 version
  • Removing the override keyword from the offending initializer in my ExtendedFormLabelHeaderView class will give a different error for the first line: Initializer 'init(reuseIdentifier:)' with Objective-C selector initWithReuseIdentifier:' conflicts with implicit initializer 'init(reuseIdentifier:)' from superclass
Max
  • 21
  • 4
  • Are these classes in different .swift files? Just make the `init` functions public. – rmaddy Nov 09 '16 at 00:38
  • Yes they are in different swift files: Every class above `// my app code` is located in a different file of the Former cocoapod. I added the public keyword to the initializers but it doesn't seem make a difference, the compiler keeps complaining. (I've edited the example so that they are now public initializers) – Max Nov 09 '16 at 11:43
  • I now tried working around the problem by having `ExtendedFormLabelHeaderView` extend `FormHeaderFooterView` bypassing `FormLabelHeaderView` altogether. So basically I imitate `FormHeaderFooterView` from the Former framework in my app, but now it complains that `open func setup()` defined in the framework's `FormHeaderFooterView` class cannot be overriden by my app's `ExtendedFormLabelHeaderView` class because according to the compiler the parent setup method isn't defined as open... It's almost as if pod inheritance is broken! (also updated Former they removed the init declarations, so do I) – Max Nov 09 '16 at 13:43
  • I now worked around all problems by just extending `UITableViewHeaderFooterView` and copying all functionality from intermediate classes – Max Nov 09 '16 at 14:21

0 Answers0