Here is some code from a project that, as you see it here, worked fine in Swift 2.3. Having now upgraded the project to Swift 3.0, this is producing an infinite loop at self.init()
.
class MyView: UIView
{
fileprivate let foo: String
required init? ( coder aDecoder: NSCoder )
{
fatalError( "init( NSCoder ) has not been implemented" )
}
convenience init ()
{
self.init()
foo = "bar"
}
}
I am told this should have infinite looped in Swift 2.3 too. Fair enough, I believe it, all I am able to tell you is that it didn't, but I don't know why. The possible solutions suggested in this post - Initializing swift class in objective c project causes infinite loop - are not useful because:
the
convenience init()
method in question really is a convenience init;self.init( frame: )
produces the buildtime error messageIncorrect argument label in call (have 'frame:', expected 'coder:')
, and;I have no instance of
NSCoder
to pass intoself.init( coder: )