我收到了这个错误:
警告:无法加载任何Objective-C类信息
也
线程1:EXC_BAD_ACCESS(代码= 2,地址= 0x7fff5588dfb8)
...分配此课程时:
import UIKit
import QuartzCore
class CERangeSliderKnobLayer: CALayer {
var highlighted = false
weak var slider = CERangeSlider()
}
对于这样的变量:
import UIKit
class CERangeSlider: UIControl {
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
var maximumValue = CGFloat()
var minimumValue = CGFloat()
var upperValue = CGFloat()
var lowerValue = CGFloat()
var trackLayer = CERangeSliderKnobLayer()
var upperKnobLayer = CERangeSliderKnobLayer()
var lowerKnobLayer = CERangeSliderKnobLayer()
...
}
这没有任何意义。在我的项目中,我所知道的任何地方都没有Objective C.这都是斯威夫特。
更新
如果你不像那样初始化它们,而是像这样写,即
var trackLayer: CERangeSliderKnobLayer!
然后你得到一个错误:
致命错误:在解包可选值时意外发现nil
类似于:
trackLayer.backgroundColor = UIColor.blueColor().CGColor
答案 0 :(得分:0)
出于某种原因,答案是改变我的类,以便弱属性未初始化:
import QuartzCore
class CERangeSliderKnobLayer: CALayer {
var highlighted = false
weak var slider: CERangeSlider!
}