훌이
후리스콜링개발
훌이

블로그 메뉴

  • 왈 (iOS APP)
  • Github
전체 방문자
오늘
어제
  • 전체 (171)
    • ⭐️ 개발 (140)
      • JAVA (4)
      • Web (5)
      • iOS & Swift (94)
      • iOS Concurrency (4)
      • Rx (18)
      • Git (6)
      • WWDC (1)
      • Code Refactor (3)
      • Server (1)
    • ⭐️ Computer Science (22)
      • 운영체제 (10)
      • 네트워크 (5)
      • PS (7)
    • 경제시사상식 (8)
    • 기타 등등 (0)

인기 글

최근 글

05-21 15:48

티스토리

hELLO · Designed By 정상우.
훌이

후리스콜링개발

⭐️ 개발/iOS & Swift

[iOS] Enum으로 코드 리팩토링

2022. 7. 19. 10:24
728x90
반응형

주의 : 코드만 있음!!

 

import UIKit

enum SettingOptions: Int, CaseIterable {
    case total, personal, other
    
    var section: String {
        switch self {
        case .total: return "전체 설정"
        case .personal: return "개인 설정"
        case .other: return "기타"
        }
    }
    
    var rowTitle: [String] {
        switch self {
        case .total: return ["공지사항", "실험실", "버전 정보"]
        case .personal: return ["개인/보안", "알림", "채팅", "멀티프로필"]
        case .other: return ["고객센터/도움말"]
        }
    }
}
class AssignmentTableViewController: UITableViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return SettingOptions.allCases.count
    }
    
    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return SettingOptions.allCases[section].section
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return SettingOptions.allCases[section].rowTitle.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "assignmentCell")!
        cell.textLabel?.textColor = .lightGray
        cell.textLabel?.font = .boldSystemFont(ofSize: 12)
        cell.textLabel?.text = SettingOptions.allCases[indexPath.section].rowTitle[indexPath.row]
        
        return cell
    }
}
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'⭐️ 개발 > iOS & Swift' 카테고리의 다른 글

[Swift] 타입 프로퍼티 왜 씀?  (0) 2022.07.21
[iOS] cell shadow + cornerRadius 같이 주는 방법  (0) 2022.07.21
[iOS] for - in / forEach 동작구조?  (0) 2022.07.19
[iOS] Formatted API in iOS15  (0) 2022.07.13
[iOS] Copy items if needed, Move to Trash  (0) 2022.07.13
    '⭐️ 개발/iOS & Swift' 카테고리의 다른 글
    • [Swift] 타입 프로퍼티 왜 씀?
    • [iOS] cell shadow + cornerRadius 같이 주는 방법
    • [iOS] for - in / forEach 동작구조?
    • [iOS] Formatted API in iOS15
    훌이
    훌이

    티스토리툴바