代码:
import UIKit class MessageBubbleView: UIView { overrideinit(frame: CGRect, message:Message) { self.message = message bubbleImageView = super.init(frame: frame) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
出错:
Initializer does not override a designated initializer from its superclass
如图:
想要搞懂:
到底如何写init函数
ios – Initializer does not override a designated initializer from its superclass – Stack Overflow
swift – Build error when trying to override an initializer in Xcode 6.3 Beta 3 – Stack Overflow
最后用:
import UIKit class MessageBubbleView: UIView { var message:Message? = nil var displayTextView:UITextView? = nil var bubbleImageView:UIImageView? = nil let font:UIFont? = nil override init(frame: CGRect) { super.init(frame: frame) } convenience init(frame: CGRect, message: Message) { self.init(frame: frame) self.message = message bubbleImageView = UIImageView() self.addSubview(bubbleImageView!) displayTextView = UITextView() displayTextView!.textColor = UIColor(white: 0.143, alpha: 1.0) displayTextView!.backgroundColor = UIColor.clearColor() displayTextView!.selectable = false displayTextView!.font = UIFont.systemFontOfSize(12) self.addSubview(displayTextView!) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }
才通过编译。
转载请注明:在路上 » 【已解决】swift代码出错:Initializer does not override a designated initializer from its superclass