UIView
inherits from UIResponder
which inherits from NSObject
.
The NSObject.init()
initializer is accessible on UIView
, but not on subclasses of NSObject
which replace this designated initializer.
Let's consider an example.
class A: NSObject {
init(_ string: String) { }
}
This leads to a compiler error for let a = A()
- missing argument #1 for initializer because this initializer replaces the designated init()
initializer for NSObject
in the subclass.
You just need to define the initializer of the subclass as a convenience
initializer:
class A: NSObject {
convenience init(_ string: String) {
self.init() // Convenience initializers must call a designated initializer.
}
}
let a = A()
now compiles.
UIView
can also compile with other designated initializers defined in the subclass, since it's designated initializer is not known at compile time. As per the docs, if instantiating programmatically, init(frame:)
is the designated initializer, otherwise init()
is the designated initializer. This means that UIView
inherits the NSObject
designated initializer rather than replacing it as in the above example.
In your example:
class SquadHorizontalScrollViewCell: UIView {
init(var: FIRDataSnapshot){
super.init()
We see that the designated initializer is init(frame: CGRect)
, so you have to call this designated initializer instead.