Repository navigation
refactor(font): Tuist auto-registration 경로로 전환 - #101
Conversation
Font.hanSansNeo()가 UIFont(name:size:)를 직접 호출하여 수동 registerAllCustomFonts() 필요했던 문제 수정. DesignSystemFontConvertible 경로를 사용하여 자동 등록되도록 변경. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
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.
| 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)) |
There was a problem hiding this comment.
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)
Summary
Font.hanSansNeo()가UIFont(name:size:)직접 호출 →DesignSystemFontConvertible.font(size:)경로로 변경registerAllCustomFonts()호출 없이 커스텀 폰트 자동 로드Test plan
🤖 Generated with Claude Code