以最短的代码形式多次访问类型成员

时间:2017-11-14 15:38:55

标签: swift

我可以用更简短的形式编写以下代码行吗?

self.settings.style.buttonBarBackgroundColor = .white
self.settings.style.buttonBarItemBackgroundColor = .white
self.settings.style.selectedBarBackgroundColor = selectedColor

var st = self.settings.style
st.buttonBarBackgroundColor = .white
st.buttonBarItemBackgroundColor = .white
st.selectedBarBackgroundColor = selectedColor

理想情况是这样的:

self.settings.style {
    .buttonBarBackgroundColor = .white
    .buttonBarItemBackgroundColor = .white
    .selectedBarBackgroundColor = selectedColor
}

0 个答案:

没有答案