[lib] Then란?

Then

사용법

  1. CocoaPods으로 Then 설치
pod 'Then'
  1. 예제
import Then

final class MyViewController: UIViewController {

  let titleLabel = UILabel().then {
    $0.textColor = .black
    $0.textAlignment = .center
  }

  let tableView = UITableView().then {
    $0.backgroundColor = .clear
    $0.separatorStyle = .none
    $0.register(MyCell.self, forCellReuseIdentifier: "myCell")
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    self.view.addSubview(self.titleLabel)
    self.view.addSubview(self.tableView)
  }
}

Then을 사용하지 않을때

private let textLabel2: UILabel = {
    let label = UILabel()
    label.text = "test"
    label.isUserInteractionEnabled = true
    label.textColor = .black
    return label
}()

Then을 사용할 때

private let textLabel1 = UILabel().then {
    $0.text = "test1"
    $0.isUserInteractionEnabled = true
    $0.textColor = .black
}

Then git 주소

https://github.com/devxoul/Then