강민수
    • 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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    @llingo 안녕하세요 링고 거의 일주일만에 다시 PR을 보내네요😅 이번 STEP은 처음 앱을 만드는 과정이고 여러가지 시행착오를 많이 겪다보니 궁금한 내용도 많고 여러가지 생각한 내용과 방법들이 많아서 너무 두서없이 작성한 PR내용도 좀 많은 것 같습니다. 이번주도 지난주처럼 좋은 리뷰 부탁드립니다.🙏🙏 ## STEP2 내용 및 핵심경험 * ‘재고수정’ 버튼을 터치하면 ‘재고 추가’ 화면으로 이동합니다. 1. 이동 방식은 어떤 방식이 적절할까요? * 각 주문 버튼 터치 시 1. 쥬스 재료의 재고가 있는 경우 : 쥬스 제조 후 “*** 쥬스 나왔습니다! 맛있게 드세요!” 얼럿 표시 2. 쥬스 재료의 재고가 없는 경우 : “재료가 모자라요. 재고를 수정할까요?” 얼럿 표시 1. ‘예’ 선택시 재고수정화면으로 이동 2. ‘아니오’ 선택시 얼럿 닫기 * 과일쥬스를 제조하여 과일의 재고가 변경되면 화면의 적절한 요소에 변경사항을 반영합니다. * 이번 스텝 수행 중 핵심 경험 1. 내비게이션 바 및 바 버튼 아이템의 활용 2. 얼럿 컨트롤러 활용 3. Modality의 활용 4. 화면 사이의 데이터 공유 ## 해결하지 못한 점 ### 데이터 업데이트 * 저희 코드에서 Label들을 업데이트 해주는 함수가 있습니다. 업데이트를 하게 될 때 변경되지 않은 데이터들까지 불필요하게 변경해주는 것 같습니다. ```swift func updateLabel(juice: [Fruit: Int]) { guard let strawberry = juice[.strawberry], let banana = juice[.banana], let kiwi = juice[.kiwi], let pineapple = juice[.pineapple], let mango = juice[.mango] else { return } strawberryLabel.text = String(strawberry) bananaLabel.text = String(banana) kiwiLabel.text = String(kiwi) pineappleLabel.text = String(pineapple) mangoLabel.text = String(mango) } ``` * 이러한 점은 step2에서는 FruitStockViewController화면에서 재고변경이 이루어지지 않아 아직까진 문제가 없다고 판단했습니다. 하지만 step3에서 재고변경이 이루어 진다면 기능 저하를 만들어낼 문제라고 생각하여 해결하지 못한 점으로 남겼습니다. * 이런 기능저하를 방지하고자 하나의 label만 변경하는 함수를 만들어서 사용하는게 맞을지? 실제로 대부분의 앱에서 여러 데이터중 하나의 데이터만 변경이 되면 하나의 데이터만 변경을 해주는지? 아니면 전부 다 변경을 해주는지에 대해 의문이 있습니다. ## 고민한점 && 조언을 얻고 싶은 부분 ### 화면 사이의 데이터 공유 * 화면 사이의 데이터를 공유하는 방법(다음 뷰컨트롤러의 인스턴스에 할당, 싱글톤, KVO, NotificationCenter 등)에는 여러가지가 있지만 저희가 생각한 방법은 NotificationCenter 방식이랑 singleton 패턴을 사용하는 방식 두가지였습니다. 다만 아직 Notification방식과 다음 뷰컨트롤러에 인스턴스를 할당하는 방식에는 익숙치 않아서 singleton패턴을 사용하여 데이터 공유를 하였습니다. * 싱글톤을 씀으로 기존 코드에 많은 것을 추가하지 않아도 쉽게 사용가능하고 코드도 짧기 때문에 우선적으로 사용했습니다만, FruitStore의 추가 인스턴스를 못만든다는 점, 각각 클래스가 하나의 인스턴스를 바라보기 때문에 의존성이 높아진다는 단점이 있는데 혹시 어떤 방법을 가장 많이 사용할까요? * 우선 위 여러 방법(다음 뷰 컨트롤러에 인스턴스 할당, 싱글톤, KVO, NotificationCenter)중에 혹시 어떤 방법을 추천해주실 수 있을까요? ### 화면 전환 방식 * 화면 전환 방식 중 Navigation과 Modal방식에 대해 고민했습니다. 우선 Modal은 사용자에게 순간 집중을 할 수 있게 해주는 요소이고, Navigation은 정보의 깊이를 표현할 때 좋은 화면전환 방식이라고 생각해 Navigation방식을 사용했습니다. * 이런 화면전환에 대한 고민이 끝나고 난 이후에는 어떻게 구현할 것인지에 대해 많은 고민을 했습니다. * 스토리보드에서 Segue를 구현하는 방법, 코드로 Segue를 구현하는 방법, alertController를 보여주는 것 처럼 단순하게 present하는 방법, navigationController를 사용하여 pushViewController를 사용하는 방법등에 관해 고민했습니다. 다만, 이미 UI가 구성되어 있고 NavigationController가 스토리보드 내에 있었기 때문에 이 중 두가지 방법을 사용했습니다. * 우선 메인화면의 ```재고수정```버튼의 경우 간단하고 스토리보드로 한눈에 볼 수 있게 스토리보드 내에서 Segue로 구현하였습니다. * 그 외에 실패alert가 나타나서 예를 누를 경우 ```swift let okAction = UIAlertAction(title: "네", style: .default) { (action) in guard let fruitStockViewController = self.storyboard?.instantiateViewController(withIdentifier: "FruitStockViewController") else { return } self.navigationController?.pushViewController(fruitStockViewController, animated: false) } ``` * 다음과 같이 FruitStockViewController의 인스턴스를 받아와 Navigation컨트롤러를 이용하는 pushViewController를 사용하는 방법을 택했습니다. * 이런경우 두가지 방법으로 하나의 결과(FruitStockViewController를 출력)를 내는 방법으로 작성되어 있는데, 이것을 통일시켜 줘야할까요? 아니면 NavigationController를 사용하여 Navigation방식으로 화면전환한다는 결과는 같기 때문에 굳이 통일시켜줄 필요가 없을까요? * 스토리보드 내에서 Segue를 사용한 큰 이유는 앱이 어떤흐름을 가지는지 볼 수 있다는 큰 장점이 있어서 사용했고 alertAction내에서는 스토리보드로 만들 수 없기 때문에 위와 같이 사용을 했는데 어떻게 생각하시나요? ### 뷰의 생명주기 ```swift override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) updateLabel(juice: juiceMaker.getFruitsInStore()) } ``` * 재고수정(FruitStockViewController)에서 메인화면(ViewController)로 넘어갈 경우 데이터는 업데이트 되었지만 UILabel에는 업데이트 되지않아서 관련된 방법을 찾아보다가 뷰의 생명주기에 대해 보게 되었습니다. * viewDidLoad()메소드는 뷰가 처음 Load되고 나서만 실행이 되고, 만약 재고수정(FruitStockViewController)에서 메인화면으로 다시 이동한다면 이미 Load된 상태여서 동작이 안한다는 걸 봤고, [viewWillAppear](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621510-viewwillappear)과 관련해서 뷰가 계층에 추가되는 시점?, 뷰가 보여지기 직전에 호출된다는 것을 보고 사용하였습니다. ### 최대한 적은 수의 함수 사용하기 * 현재 메서드 구현을 살펴보면 하나로 묶여서 실행하는 것을 볼 수 있습니다. * 위 함수를 작성 전 처음에는 각 버튼마다 "@IBAction" 메소드를 만들어서 실행시키려고 했습니다. * 그런데 그럴 경우 같은 동작을 하는 함수임에도 불구하고 여러개가 있는게 가독성이나 코드 길이나 너무 불필요하다고 생각하여 이 부분을 해결할 방법을 찾았습니다. * UIButton은 라벨이 있다면 titleLabel?.text로 해당 텍스트를 불러 올 수 있다는 것을 보고 쥬스를 만드는 모든 버튼을 연결하여 사용하기로 했습니다. * 이러한 경우 기능성, 가독성 측면에서는 좋아보일 수 있으나 나중에 과일이 추가 되거나 버튼의 기능이 변경되면 리팩토링하는데 어려움을 겪을것 같습니다. * 단순히 버튼의 라벨 텍스트를 불러와서 사용을 했지만 만약 버튼에 라벨텍스트가 없다면 viewController처럼 고유 ID를 사용하여 쓰는게 좋은지 아니면 그 외 다른 방법이 있는지 궁금합니다 ```swift @IBAction func clickButton(_ sender: UIButton) { guard let buttonLabel = sender.titleLabel?.text, let juice = decideOrderJuice(buttonLabel) else { return } tryMakeJuice(juice) } func decideOrderJuice(_ juice: String) -> Juice? { switch juice { case "딸바쥬스 주문": return .strawberryBananaJuice case "딸기쥬스 주문": return .strawberryJuice case "바나나쥬스 주문": return .bananaJuice case "파인애플쥬스 주문": return .pineappleJuice case "망키쥬스 주문": return .mangoKiwiJuice case "키위쥬스 주문": return .kiwiJuice case "망고쥬스 주문": return .mangoJuice default: return nil } } ``` * 만약 분리를 한다면 이렇게 아래의 코드같이 구현할 것 같습니다. ```swift @IBAction func clickStrawberryOrderButton() { // 기능 구현 } @IBAction func clickStrawberryBananaOrderButton() { // 기능 구현 } @IBAction func clickPineappleOrderButton() { // 기능 구현 } @IBAction func clickKiwiOrderButton() { // 기능 구현 } ```

    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