0
我無法將Swift 2.1中的代碼翻譯成Swift 3.0。我在塊「lazy var」(第3行和第4行)上發現錯誤。錯誤消息:「實例成員'çontentView'不能用於類型'MyView'」。遷移Swift 2.1到Swift 3.0
但在Swift 2.1中的代碼工作。
有人可以幫助我嗎?
我的代碼:
@IBDesignable 類MyView的:UIView的{
private lazy var __once:() = {() -> Void in
let bundle = Bundle(for: type(of: self))
MyView.contentView = UINib(nibName: "MyView", bundle: bundle).instantiate(withOwner: self, options: nil)[0] as! UIView
MyView.contentView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(MyView.contentView)
let view = ["contentView": MyView.contentView]
self.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[contentView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: view))
self.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[contentView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: view))
MyView.titleMyLabel.text = MyView.myTitle
MyView.descriptionMyLabel.text = MyView.myDescription
MyView.mobileNumberLabel.text = MyView.numberMobile
MyView.myBarBotton.botaoMudou(.hight)
MyView.myBarBotton.botaoMudou(.left)
MyView.myBarBotton.botaoMudou(.center)
self.setNeedsUpdateConstraints()
}()
@IBInspectable var myTitle: String? {
didSet {
titleMyLabel.text = myTitle
}
}
@IBInspectable var myDescription: String? {
didSet {
descriptionMyLabel.text = myDescription
}
}
@IBInspectable var numberMobile: String? {
didSet {
mobileNumberLabel.text = numberMobile
}
}
@IBInspectable var rawStyleLeftButton: Int {
set(newValue) {
myBarBotton.rawstyleLeftButton = newValue
}
get {
return myBarBotton.rawstyleLeftButton
}
}
@IBInspectable var rawStyleHightButton: Int {
set(newValue) {
myBarBotton.rawstyleHightButton = newValue
}
get {
return myBarBotton.rawstyleHightButton
}
}
@IBInspectable var rawStyleCenterButton: Int {
set(newValue) {
myBarBotton.rawstyleCenterButton = newValue
}
get {
return myBarBotton.rawstyleCenterButton
}
}
@IBInspectable var titleLeftButtom: String? {
set(newValue) {
myBarBotton.myTitleBotaoEsquerdo = newValue
}
get {
return myBarBotton.myTitleBotaoEsquerdo
}
}
@IBInspectable var titleCenterButtom: String? {
set(newValue) {
myBarBotton.myTitleBotaoCentral = newValue
}
get {
return myBarBotton.myTitleBotaoCentral
}
}
@IBInspectable var titleHightButton: String? {
set(newValue) {
myBarBotton.myTitleBotaoDireito = newValue
}
get {
return myBarBotton.myTitleBotaoDireito
}
}
var styleLeftButton: styleMyBarBotton {
set(newValue) {
myBarBotton.styleLeftButton = newValue
}
get {
return myBarBotton.styleLeftButton
}
}
var styleCenterButton: styleMyBarBotton {
set(newValue) {
myBarBotton.styleCenterButton = newValue
}
get {
return myBarBotton.styleCenterButton
}
}
var styleHightButton: styleMyBarBotton {
set(newValue) {
myBarBotton.styleHightButton = newValue
}
get {
return myBarBotton.styleHightButton
}
}
fileprivate var token: Int = 0
fileprivate var contentView: UIView!
@IBOutlet weak var myBarBotton: myBarBottonView!
@IBOutlet fileprivate weak var titleMyLabel: UILabel!
@IBOutlet fileprivate weak var descriptionMyLabel: UILabel!
@IBOutlet fileprivate weak var mobileNumberLabel: UILabel!
fileprivate func initialization() {
_ = self.__once
}
override init(frame: CGRect) {
super.init(frame: frame)
initialization()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialization()
}
}