Skip to content

Instantly share code, notes, and snippets.

@skyofdwarf
Last active November 3, 2022 01:54
Show Gist options
  • Save skyofdwarf/3288b727c41aed7b94602aa5e016e789 to your computer and use it in GitHub Desktop.
Save skyofdwarf/3288b727c41aed7b94602aa5e016e789 to your computer and use it in GitHub Desktop.
SwiftGen vs R.swift 당신의 선택은?

뭘 쓸까? 일주일 후 까먹을 나를 위해 간단한 메모

  • 스토리보드, xib: SwiftGen에서 지원을 안하기 때문에 R.swift를 사용
  • 스트링: .으로 중첩구조가 가능한 SwiftGen를 선택

나머지는... R.swift? 필요할 때 더 고민하자.

SwiftGen

  • 스토리보드는 지원하지만 cell/xib 을 지원하지 않는다.
  • 스트링의 경우 '.'으로 구분된 경우 중첩타입으로 분리가능하다. 오
    // Simple strings
    let message = L10n.alertMessage
    let title = L10n.alertTitle
    
    // with parameters, note that each argument needs to be of the correct type
    let apples = L10n.Apples.count(3)
    let bananas = L10n.Bananas.owner(5, "Olivier")
  • 에셋 사용시 color, image 등의 구분자가 맨 뒤에 붙는다. 네??
    // You can create new images by referring to the enum instance and calling `.image` on it:
    let bananaImage = Asset.Exotic.banana.image
    let privateImage = Asset.private.image
    
    // You can create colors by referring to the enum instance and calling `.color` on it:
    let primaryColor = Asset.Styles.Vengo.primary.color
    let tintColor = Asset.Styles.Vengo.tint.color
    
    // You can create data items by referring to the enum instance and calling `.data` on it:
    let data = Asset.data.data
    let readme = Asset.readme.data

R.swift

  • cell, xib을 지원한다.
  • 모든 호출이 함수라서 맨 뒤에 ()을 붙여야 된다. 귀찮다.
  • SwiftGen과 다르게 color, image 구분자가 앞에 온다. 요 맘에 드네
    view.backgroundColor = R.color.primaryBackground()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment