Skip to content

Conversation

@JinUng41
Copy link
Collaborator

@JinUng41 JinUng41 commented Apr 5, 2025

👻 PULL REQUEST

📄 작업 내용

  • 기존 UITextField의 익스텐션 메서드인 setPretendard(with:)를 삭제하고, 편의 생성자를 구현하였습니다.

💻 주요 코드 설명

왜 편의생성자인가

  • UITextFieldsetPretendard(with:)을 통한 defaultTextAttributes를 설정할 때의 문제를 해결하기 위함입니다.

😂 setPretendard(with:)의 문제

  • 만약 다른 속성을 설정(예: textColor = .blue)한 후, setPretendard(with:)를 호출하여, defaultTextAttributes를 설정하면 이전에 설정한 속성을 덮어씌워버리는 문제가 발생했습니다.

😄 편의 생성자로 defaultTextAttributes의 설정 시점을 강제

  • 편의 생성자를 통해 객체 생성 초기에 defaultTextAttributes를 먼저 설정하여, 이후 속성 설정이 덮어씌워지는 문제가 없도록 하였습니다.

📍 왜 kerning만 적용했나요?

  • 텍스트필드는 1줄의 내용만을 보여주기 때문에, lineHeightbaselineOffset은 불필요하다고 생각하였습니다.
UITextField+.swift
// MARK: - Pretendard style Initializer

/// Pretendard 폰트 스타일을 적용한 UITextField를 생성하는 편의 생성자입니다.
///
/// 이 생성자는 `defaultTextAttributes`를 가장 먼저 설정하여 나중에 설정하는
/// 다른 속성(textColor, textAlignment 등)이 기존 폰트와 자간 설정을 덮어씌우지 않도록 합니다.
///
/// - Parameters:
///   - style: UIFont.Pretendard 스타일
///   - placeholder: 플레이스홀더 텍스트 (선택 사항)
///   - text: 초기 텍스트 (선택 사항)
///
/// - 사용 예시:
/// ```
/// let nameField = UITextField(pretendardStyle: .body1, placeholder: "이름을 입력하세요")
/// nameField.textColor = .black // 폰트와 자간 설정은 유지됨
/// ```
///
/// - Note: UITextField는 한 줄 텍스트만 지원하므로 baselineOffset과 lineHeight는 적용하지 않습니다.
convenience init(
    pretendard style: UIFont.Pretendard,
    placeholder: String? = nil,
    text: String? = nil
) {
    self.init(frame: .zero)
    
    let font = UIFont.pretendard(style)
    
    // 기본 속성 딕셔너리 생성 (폰트와 자간만 포함)
    let defaultAttributes: [NSAttributedString.Key: Any] = [
        .font: font,
        .kern: style.kerning
    ]
    
    // 중요: defaultTextAttributes를 가장 먼저 설정하여 다른 속성들이 이를 덮어씌우지 않도록 함
    self.defaultTextAttributes = defaultAttributes
    
    self.font = font
    
    if let placeholder {
        self.attributedPlaceholder = NSAttributedString(string: placeholder, attributes: defaultAttributes)
    }
    
    if let text {
        self.text = text
    }
}

🔗 연결된 이슈

Summary by CodeRabbit

  • New Features

    • Updated text input fields now showcase a consistent and refined appearance. In the profile registration view, the text field displays an improved placeholder that guides users effectively.
  • Refactor

    • Streamlined the text field configuration for a more coherent and simplified setup across the app.

@JinUng41 JinUng41 added 🛠️ fix 기능적 버그나 오류 해결 시 사용 ♻️ refactor 기존 코드를 리팩토링하거나 수정하는 등 사용 (생산적인 경우) labels Apr 5, 2025
@JinUng41 JinUng41 added this to the 리팩토링 마감 milestone Apr 5, 2025
@JinUng41 JinUng41 requested a review from youz2me April 5, 2025 17:50
@JinUng41 JinUng41 self-assigned this Apr 5, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 5, 2025

Walkthrough

The changes refactor the way UITextField is initialized by introducing a new convenience initializer that sets the Pretendard style along with optional placeholder and text properties. The previous method setPretendard(with:) has been removed, and existing usage in the onboarding view has been updated to invoke the new initializer directly for a more concise setup.

Changes

Files Change Summary
Wable-iOS/.../Helper/Extension/UITextField+.swift Added a new convenience initializer init(pretendard:placeholder:text:) replacing the old setPretendard(with:) method and revised attribute setup.
Wable-iOS/.../Onboarding/View/ProfileRegisterView.swift Updated nickNameTextField initialization to use the new initializer with parameters pretendard: .body2 and a placeholder.

Sequence Diagram(s)

sequenceDiagram
    participant PR as ProfileRegisterView
    participant TF as UITextField
    PR->>TF: init(pretendard: .body2, placeholder: "예) 중꺾마")
    TF->>TF: Set defaultTextAttributes (font, kerning)
    TF-->>PR: Return configured UITextField
Loading

Assessment against linked issues

Objective ([#159]) Addressed Explanation
Modify UITextField extension to configure Pretendard styling via initializer

Poem

I'm a rabbit, hopping in the code garden free,
New initializers bloom like carrots for me.
Old methods retire as fresh syntax lights the way,
Each text field tuned in a bright, concise display.
With a skip and a hop, my joy overflows—
Celebrating cleaner code where the Pretendard style grows!
🐇🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Wable-iOS/Presentation/Helper/Extension/UITextField+.swift (1)

31-58: Well-designed convenience initializer that properly respects attribute precedence

This implementation correctly addresses the issue mentioned in the PR by setting font attributes first, then applying other properties. A few observations:

  1. The initializer properly handles optional parameters with default values
  2. Correctly uses the same attributes for both the text and placeholder
  3. Sets both defaultTextAttributes and font properties to ensure consistency

For even more robustness, consider adding a check to ensure text alignment is preserved:

 // 중요: defaultTextAttributes를 가장 먼저 설정하여 다른 속성들이 이를 덮어씌우지 않도록 함
 self.defaultTextAttributes = defaultAttributes
 
 self.font = font
+
+ // 텍스트 정렬 설정 보존
+ self.textAlignment = self.textAlignment

This ensures that if the default text alignment was changed before initialization, it won't be reset.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26c050b and 37ace87.

📒 Files selected for processing (2)
  • Wable-iOS/Presentation/Helper/Extension/UITextField+.swift (1 hunks)
  • Wable-iOS/Presentation/Onboarding/View/ProfileRegisterView.swift (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
Wable-iOS/Presentation/Helper/Extension/UITextField+.swift (1)
Wable-iOS/Presentation/Helper/Extension/UIFont+.swift (1)
  • pretendard (93-95)
🔇 Additional comments (2)
Wable-iOS/Presentation/Onboarding/View/ProfileRegisterView.swift (1)

42-45: Good refactoring to use the new convenience initializer

The updated code uses the new UITextField convenience initializer that accepts Pretendard style and placeholder parameters directly. This approach is more concise and prevents potential issues where setting properties after initialization might overwrite font settings.

Wable-iOS/Presentation/Helper/Extension/UITextField+.swift (1)

12-30: Excellent documentation with detailed explanations and examples

The documentation clearly explains the purpose of the initializer, why it sets defaultTextAttributes first (to prevent other properties from overwriting font settings), and provides useful examples. This level of detail is valuable for other developers using this API.

@JinUng41 JinUng41 moved this to In Review in Wable-iOS Apr 5, 2025
@JinUng41 JinUng41 moved this from In Review to Ready for Review in Wable-iOS Apr 5, 2025
Copy link
Member

@youz2me youz2me left a comment

Choose a reason for hiding this comment

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

헉 저도 마침 UITextView 문제로 골머리를 좀 썩였는데 ... 초기화 시에 이렇게 설정해주면 좀 더 간편하게 접근할 수 있겠네요! 저도 사용할 곳이 있다면 유용하게 사용해보겠습니닷 ㅎㅎ

@github-project-automation github-project-automation bot moved this from Ready for Review to In Review in Wable-iOS Apr 5, 2025
@JinUng41 JinUng41 merged commit c40ab52 into develop Apr 5, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Wable-iOS Apr 5, 2025
@JinUng41 JinUng41 deleted the fix/#159-uitextfield-extension branch April 5, 2025 18:07
youz2me pushed a commit that referenced this pull request Oct 26, 2025
[Fix] UITextField 익스텐션 메서드 수정
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🛠️ fix 기능적 버그나 오류 해결 시 사용 ♻️ refactor 기존 코드를 리팩토링하거나 수정하는 등 사용 (생산적인 경우)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Fix] UITextField의 익스텐션 수정

3 participants