Swift if複数条件をswitchへ、最初からそう書けよって。。。
リファクタリング前
if self.notebook.orientation == .portrait {
if self.notebook.unit == .day {
self.image(assetname: "Default Template Portrait Day")
}
else {
self.image(assetname: "Default Template Portrait")
}
}
else {
if self.notebook.unit == .day {
self.image(assetname: "Default Template Landscape Day")
}
else {
self.image(assetname: "Default Template Landscape")
}
}
リファクタリング後
switch (self.notebook.orientation, self.notebook.unit) {
case (.portrait, .day):
self.image(assetname: "Default Template Portrait Day")
case (.portrait, .week):
self.image(assetname: "Default Template Portrait")
case (.landscape, .day):
self.image(assetname: "Default Template Landscape Day")
case (.landscape, .week):
self.image(assetname: "Default Template Landscape")
}