Skip to content

refactor(font): Tuist auto-registration 경로로 전환 - #101

Merged
gomminjae merged 1 commit into
developfrom
refactor/font-auto-registration
May 31, 2026
Merged

gomminjae merged 1 commit into
developfrom
refactor/font-auto-registration

Conversation

@gomminjae

Copy link
Copy Markdown
Collaborator

Summary

  • Font.hanSansNeo()가 UIFont(name:size:) 직접 호출 → DesignSystemFontConvertible.font(size:) 경로로 변경
  • Tuist 생성 코드의 auto-registration이 동작하여, Example 앱에서도 별도 registerAllCustomFonts() 호출 없이 커스텀 폰트 자동 로드
  • 이모지 cascade fallback 로직 유지

Test plan

  • 메인 앱에서 SpoqaHanSansNeo 폰트 정상 렌더링 확인
  • Example 앱에서 커스텀 폰트 정상 로드 확인
  • 이모지가 포함된 텍스트에서 fallback 정상 동작 확인

🤖 Generated with Claude Code

Font.hanSansNeo()가 UIFont(name:size:)를 직접 호출하여
수동 registerAllCustomFonts() 필요했던 문제 수정.
DesignSystemFontConvertible 경로를 사용하여 자동 등록되도록 변경.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the hanSansNeo font helper in Font.swift to use DesignSystemFontConvertible instead of hardcoded string names. The review feedback highlights a potential crash risk: convertible.font(size:) can trigger a fatalError if the font resource fails to load (e.g., in SwiftUI Previews or test environments). It is recommended to safely instantiate the font using UIFont(font:size:) and provide a fallback option to prevent runtime crashes.

Comment on lines +15 to +22
let baseFont = convertible.font(size: size)
let cascadeKey = UIFontDescriptor.AttributeName(rawValue: "NSCTFontCascadeListAttribute")
let emojiFontDescriptor = UIFontDescriptor(fontAttributes: [.name: "AppleColorEmoji"])
let systemFontDescriptor = UIFont.systemFont(ofSize: size).fontDescriptor
let descriptor = baseFont.fontDescriptor.addingAttributes([
cascadeKey: [emojiFontDescriptor, systemFontDescriptor]
])
return Font(UIFont(descriptor: descriptor, size: size))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

convertible.font(size:) 메서드는 내부적으로 폰트 로드에 실패할 경우 fatalError를 발생시켜 앱을 강제 종료합니다. 특정 테스트 환경이나 SwiftUI Preview 등에서 리소스 번들이 정상적으로 로드되지 않는 상황이 발생하면 앱이 크래시될 위험이 있습니다.

기존 코드처럼 안전하게 옵셔널 바인딩을 사용하거나, 실패 시 시스템 폰트 또는 .custom 폰트로 fallback할 수 있도록 UIFont(font:size:) 이니셜라이저를 사용하는 것이 더 안전합니다.

        if let baseFont = UIFont(font: convertible, size: size) {
            let cascadeKey = UIFontDescriptor.AttributeName(rawValue: "NSCTFontCascadeListAttribute")
            let emojiFontDescriptor = UIFontDescriptor(fontAttributes: [.name: "AppleColorEmoji"])
            let systemFontDescriptor = UIFont.systemFont(ofSize: size).fontDescriptor
            let descriptor = baseFont.fontDescriptor.addingAttributes([
                cascadeKey: [emojiFontDescriptor, systemFontDescriptor]
            ])
            return Font(UIFont(descriptor: descriptor, size: size))
        }
        return .custom(convertible.name, size: size)

@gomminjae
gomminjae merged commit 3e41c86 into develop May 31, 2026
2 checks passed
@gomminjae
gomminjae deleted the refactor/font-auto-registration branch May 31, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant