我有简单的评分应用程序,我有;
@IBInspectable var commingId: Int
{
get
{
return self.commingId;
}
set
{
refreshStars()
}
}
func starClicked(sender:UIButton){
if(self.canEdit){
rating = sender.tag;
if(self.delegate != nil){
self.delegate.starRateEdited(Double(rating))
}
self.refreshStars()
print("Selected \(sender.tag) - commingId \(self.commingId)")
}
}
代码。当我尝试获得回报时,
self.commingId
给了我;EXC_BAD_ACCESS(代码= 2,地址= 0x7fff571egff8)错误
如何在其中获取
commingId
? 最佳答案
Why do you even redefined getter?
看起来您只需要在设置值后调用refreshStars()
,因此只需使用willSet/didSet
@IBInspectable var commingId: Int {
didSet {
refreshStars()
}
}