Rowan
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 계산기 II ## 목차 1. [소개](#1-소개) 2. [팀원](#2-팀원) 3. [타임라인](#3-타임라인) 4. [프로젝트 구조](#4-프로젝트-구조) 5. [실행화면(기능 설명)](#5-실행-화면기능-설명) 6. [트러블슈팅](#6-트러블-슈팅) 7. [참고링크](#7-참고-링크) <br/> ## 1. 소개 각자 작성한 계산기 앱 코드를 병합하여 리팩토링한 프로젝트 ### Common * [protocol] **CalculateItem** - 빈 프로토콜 정의를 통해 Generic Constraint로 활용하여 Generic에 들어갈 수 있는 데이터 타입을 한정시키는 기능 * [extension] **NumberFormatter** - String, Double 변환 및 decimal표현 기능 * [enum] **Sign** - 전역의 Magic Literal/Number 처리를 위한 NameSpace * [typealias] **CurrentItem** - 코드의 가독성을 높이기 위한 `(operatorText: String, operandText: String)` 튜플 타입의 별칭 <br/> ### Model * [struct] **CalculatorItemQueue** - Array DoubleStack을 활용한 queue 자료구조를 구현 - 제네릭으로 정의하여 확장성 확보 - TDD(Test-Driven Development)를 통해 메서드를 정의하여 안정성 확보 * [enum] **Operator** * 사칙 연산을 case로 분류해 case별 연산 기능을 제공하는 타입 * [struct] **Formula** * Queue 내부 데이터를 추출하여 연산 결과를 얻는 기능 * [enum] **ExpressionParser** * 연산식을 숫자와 연산기호로 분리하여 Formula 타입을 반환하는 기능 * 인스턴스 없이 전역에서 접근 가능하도록 case없는 열거형 static 메서드 정의 * [class]] **InputManager** * ExpressionParser에 전달할 input을 관리하는 객체 <br/> ### View * [UIScrollView] **CalculateItemScrollView** * 스크롤 화면을 넘어가는 데이터가 추가될 때마다 스크롤을 최하단으로 유지하는 기능 * [UIStackView] **CalculcateItemStackView** * subview의 추가/제거 기능 <br/> ### Controller * [UIViewController] **MainViewController** * 계산기 User Event 처리를 담당하는 객체 * 각 버튼 별 발생한 이벤트를 적절히 처리하는 기능 * view의 초기 화면을 설정하는 기능 <br/> ## 2. 팀원 | Rowan | sehong | | :--------: | :--------: | | <Img src = "https://i.imgur.com/S1hlffJ.jpg" width="200" height="200"/> |<Img src ="https://i.imgur.com/64dvDJl.jpg" width="200" height="200"/> | [Github Profile](https://github.com/Kyeongjun2) |[Github Profile](https://github.com/sehoong0429) <br/> ## 3. 타임라인 **프로젝트 진행 기간** - **23.02.06 (월) ~ 23.02.10 (금)** > 23.02.06 (월): 각자의 계산기 프로젝트 Merge, 리팩토링 및 STEP1 PR 작성 <br/> > 23.02.07 (화): STEP1 PR 피드백 반영, 계산기 작동 실험 후 리팩토링(1회 계산 이후 IBAction 조건 추가) <br/> > 23.02.09 (목): 리팩토링 및 STEP2 PR 작성 <br/> > 23.02.10 (금): PR 피드백 반영, README 작성 <br/> ## 4. 프로젝트 구조 #### UML ![](https://i.imgur.com/lfQpFdC.jpg) #### 파일 구조 ``` ├── Calculator │   ├── App │   │   ├── AppDelegate │   │   └── SceneDelegate │   ├── Common │   │   ├── Extension │   │   ├── Protocol │   │   ├── Sign │   │   └── Typealias │   ├── Controller │   │   └── MainViewController │   ├── Models │   │   ├── CalculatorItemQueue │   │   ├── ExpressionParser │   │   ├── Formula │   │   ├── InputManager │   │   ├── Operator │   │   └── ViewGenerator │   ├── Views │   │ ├── CalculateItemScrollView │   │ └── CalculateItemStackView │   ├── Info.plist │   ├── Assets │   └── Base │      ├── LaunchScreen │      └── Main └── CalculatorTests ├── CalculatorTests.swift ├── ExpressionParserTests.swift └── FormulaTests.swift ``` <br/> ## 5. 실행 화면(기능 설명) | 숫자, 기능 버튼 동작 | 0, 00, . 버튼 실행 화면 | | :--------: | :--------: | | <Img src = "https://i.imgur.com/AzufZVQ.gif" width="300" height="450"/> | <Img src = "https://i.imgur.com/YBn1Ob5.gif" width="300" height="450"/> | | 예외처리 | 스크롤 뷰 동작 | | :--------: | :--------: | | <Img src = "https://i.imgur.com/OiLIDrE.gif" width="300" height="450"/> | <Img src = "https://i.imgur.com/Vxp2MAD.gif" width="300" height="450"/> | * 숫자가 0인 경우 연산자 변경, 0으로 나눈경우 NaN 예외처리 * 스크롤뷰의 서브 뷰가 스크롤뷰 영역을 넘어가는 경우 항상 최하단으로 스크롤 이동 <br/> ## 6. 트러블 슈팅 ### Merge Conflict 프로젝트 초기 Merge 과정에서 PR을 통한 코드 병합 중, 계속 Conflict가 발생했습니다. 서로의 프로젝트 파일 구조, 이름이 다르기 때문에 발생한 문제였다고 생각하여 conflict가 발생하지 않도록 팀원의 레포지토리를 로컬에 클론하여 Merge를 진행하였습니다. 또한 Terminal과 Xcode를 이용하여 직접 Conflict를 처리하기에 어려움을 느꼈습니다. 조금 더 수월한 Conflict 처리를 위해 Git 관리 Tool인 Git Fork를 사용하였습니다. <br/> ### operand button IBAction 기능 추가 저희는 리팩토링을 하면서 휴대폰에 계산기 기본 어플과 비슷하게 구현하려고 했습니다. 계산기 앱에서는 계산 결과를 받은 뒤에 숫자만 입력하면 새로운 계산이 시작되고, 계산 결과를 받은 뒤에 연산자 기호를 입력하면 결과 값을 가지고 계산이 시작되는 부분을 확인했습니다. 기존에는 결과 값을 받은 뒤에 숫자만 입력하면 숫자가 결과에 붙는 방식이었는데 이를 휴대폰 계산기앱 방식 그대로 수정하여 기능을 추가하게 되었습니다. ```swift // before @IBAction private func touchOperandButton(_ sender: UIButton) { guard let inputOperand = sender.currentTitle else { return } ... } ``` ```swift // after @IBAction private func touchOperandButton(_ sender: UIButton) { guard let inputOperand = sender.currentTitle else { return } guard isFinishedCalculation == false else { resetAll() operandLabel.text = inputOperand isFirstItem = false return } ... } ``` <br/> ### Typealias 기존에 선언되어있는 타입에 새로운 별칭을 붙여 반복되어 사용되는 코드의 길이를 줄이고 가독성을 높이려고 사용했습니다. ```swift //before calculateItemStackView.addCurrentItem(operator: currentOperator, operand: currentOperand) inputHandler.addInput(about: currentOperator, and: currentOperand) ```` ```swift // after calculateItemStackView.add(currentItem) inputHandler.addInput(about: currentItem) ``` ## 7. 참고 링크 - [Swift Language Guide - Protocols](https://docs.swift.org/swift-book/LanguageGuide/Protocols.html) - [야곰닷넷 - 오토레이아웃 정복하기](https://yagom.net/courses/autolayout/) - [야곰닷넷 - UnitTest 작성하기](https://yagom.net/courses/unit-test-%EC%9E%91%EC%84%B1%ED%95%98%EA%B8%B0/) - [NumberFormatter - Apple Devoloper Documentation](https://developer.apple.com/documentation/foundation/numberformatter) - [UIStackView - Apple Devoloper Documentation](https://developer.apple.com/documentation/uikit/uistackview) - [arrangedSubviews - Apple Devoloper Documentation](https://developer.apple.com/documentation/uikit/uistackview/1616232-arrangedsubviews) - [UIView - Apple Devoloper Documentation](https://developer.apple.com/documentation/uikit/uiview) - [layoutIfNeeded - Apple Devoloper Documentation](https://developer.apple.com/documentation/uikit/uiview/1622507-layoutifneeded) - [UIScrollView - Apple Devoloper Documentation](https://developer.apple.com/documentation/uikit/uiscrollview) - [UILabel - Apple Devoloper Documentation](https://developer.apple.com/documentation/uikit/uilabel) - [Benoit Pasquier; Data Structure - How to implement a Queue in Swift](https://benoitpasquier.com/data-structure-implement-queue-swift/) - [Kodeco - Swift Algorithm: Linked List Data Structure](https://www.kodeco.com/947-swift-algorithm-club-swift-linked-list-data-structure) - [Swift Language Guide - Types](https://docs.swift.org/swift-book/ReferenceManual/Types.html)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully