기존 폰트 extension을 리드님의 권유에 따라 리팩토링하면서 line height를 다루었는데, lineheight를 지정해주는 게 처음이라서 어떤 방식으로 설정해주어야하는 지 찾아보았습니다

그 중 switch 방식과 dictionary 방식에 대해 어떤 것이 더 알맞을 지 고민해보았습니다.

static func pretendard(_ style: UIFont.PretendardStyle, text: String) -> NSAttributedString {
        let font = UIFont.pretendard(style)
        let paragraph = NSMutableParagraphStyle()

        switch style {
        case .title1_b_17, .title2_sb_15:
            paragraph.lineHeightMultiple = 1.3
        default:
            paragraph.lineHeightMultiple = 1.4
        }

        return NSAttributedString(string: text, attributes: [
            .font: font,
            .paragraphStyle: paragraph
        ])
    }
private static let lineHeightMap: [UIFont.PretendardStyle: CGFloat] = [
    .title1_b_17: 1.3,
    .title2_sb_15: 1.3,
    .title3_b_15: 1.4,
    .body1_sb_15: 1.4,
   ...
]

static func pretendard(_ style: UIFont.PretendardStyle, text: String) -> NSAttributedString {
    let font = UIFont.pretendard(style)
    let paragraph = NSMutableParagraphStyle()
    paragraph.lineHeightMultiple = lineHeightMap[style] ?? 1.4

    return NSAttributedString(string: text, attributes: [
        .font: font,
        .paragraphStyle: paragraph
    ])
}

위와 같이 두 방식을 고민한 결과, 현재 진행 중인 프로젝트에서는 폰트 스타일이 고정되어있기 때문에switch를 사용하는 것이 효율적이라고 판단하여 해당 방식으로 채택하였습니다.