Created
August 9, 2015 13:31
-
-
Save hachinobu/6d7b1ad92efe8a13164b to your computer and use it in GitHub Desktop.
TableViewのsectionとrowの情報をEnumを利用して定義してみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TableSectionRowInfo { | |
enum RowInfo { | |
case SecOne1 | |
case SecOne2 | |
case SecTwo1 | |
case SecTwo2 | |
case SecTwo3 | |
func rowCount() -> Int { | |
switch(self) { | |
case .SecOne1: | |
return 1 | |
case .SecOne2: | |
return 2 | |
case .SecTwo1: | |
return 3 | |
case .SecTwo2: | |
return 4 | |
case .SecTwo3: | |
return 5 | |
} | |
} | |
} | |
enum SectionInfo { | |
case SecOne(RowInfo) | |
case SecTwo(RowInfo) | |
func rowCount() -> Int { | |
switch(self) { | |
case .SecOne(let row): | |
return row.rowCount() | |
case .SecTwo(let row): | |
return row.rowCount() | |
} | |
} | |
} | |
var sectionInfo: SectionInfo | |
func row() -> Int { | |
return sectionInfo.rowCount() | |
} | |
} | |
let tableinfo = TableSectionRowInfo(sectionInfo: .SecOne(.SecOne1)) | |
tableinfo.row() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment