Hyun A Song
    • 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
    ###### tags: `study` # 23.04.29 Optional ## 팀규칙 - 스터디 참여에 변동 사항이 있을 시 전날 미리 말해주기 - 스터디 전 실험실 유의사항 예습해오기(바로 실험 가능하게 준비해오기) - 스터디 시간 | 시간 | 할 일 | | :-----------: | :---: | | 09:00 ~ 09:10 | 복습 리뷰 | | 09:10 ~ 10:00 | 타임 1 | | 10:00 ~ 10:10 | 브레이크타임 | | 10:10 ~ 11:00 | 타임 2 | | 11:00 ~ 11:10 | 브레이크타임 | | 11:10 ~ 12:00 | 타임 3 | ## 참여자 | Hemg🐻 | hoon🤪 | [Serena🐷](https://github.com/serena0720) | 비모🤖 | | -------- | -------- | -------- | ---- | --- ## Optional ### 실험 진행을 위해 알고 있어야 할 주요 개념 - 함수의 생성과 호출 - 함수의 전달인자(argument), 매개변수(parameter), 반환값(return) - Swift 기본 자료형 - 비교 연산자 ### 실험 1: 옵셔널 값을 사용해 봅시다. ```swift var productsList: [String?] = ["볼펜", "텀블러", "다이어리", "에코백", "머그컵", "후드집업"] ``` ### 실험 2: Optional을 활용한 경우 예외사항을 처리해 봅시다. ```swift var budget: Int = 2000 var productsList: [String?] = ["볼펜", "텀블러", "다이어리", "에코백", "머그컵", "후드집업"] func buy(productNumber: Int) { // Todo } ``` ## 📚 참조링크 - [🍎Apple Docs: error handling](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/errorhandling) - [🍎Apple Docs: optionalchaining](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/optionalchaining/) - [🍎Apple Docs: Result](https://developer.apple.com/documentation/swift/result) - [📘blog: result type](https://velog.io/@un1945/Swift-Result-Type) # README # :fire: 불타는 토요 스터디 9기 B반 :fire: > 매주 토요일 오전 9시에 스터디를 진행합니다. 사전에 제공된 자료를 바탕으로 예습하고 토론합니다. ## 🍀 스터디원 |[Hemg🐻](https://github.com/hemg2)|[hoon🐶](https://github.com/Hoon94)|[Serena🐷](https://github.com/serena0720)|[비모🤖](https://github.com/bubblecocoa)| |:-----:|:------:|:--------:|:----:| |<Img src="https://avatars.githubusercontent.com/u/101572902?v=4" width="150"/>|<Img src="https://cdn.discordapp.com/avatars/353059967261081600/6c1f047a3c1a95ce042b29506d14e33c.webp?size=160" width="150"/>|<Img src = "https://i.imgur.com/q0XdY1F.jpg" width="150"/>|<img width="150" src="https://avatars.githubusercontent.com/u/67216784?v=4">| --- ## 팀규칙 - 스터디 참여에 변동 사항이 있을 시 전날 미리 말해주기 - 스터디 전 실험실 유의사항 예습해오기(바로 실험 가능하게 준비해오기) - 스터디 시간 | 시간 | 할 일 | | :-----------: | :---: | | 09:00 ~ 09:10 | 복습 리뷰 | | 09:10 ~ 10:00 | 타임 1 | | 10:00 ~ 10:10 | 브레이크타임 | | 10:10 ~ 11:00 | 타임 2 | | 11:00 ~ 11:10 | 브레이크타임 | | 11:10 ~ 12:00 | 타임 3 | --- ### 📅 2023.04.29 (토) Week#1 ###### 👨‍👩‍👦‍👦 참여자 : Hemg, hoon, Serena, 비모 #### [금주 실험 주제🧑🏻‍🔬] **Optional** <br/> [WIki URL](https://github.com/HongDaeroMoiSi-jo/weekendStudy/wiki/%5Bweek01%5D-Optional) --- ### 📅 2023.05.06 (토) Week#2 ###### 👨‍👩‍👦‍ 참여자 : Hemg, hoon, Serena, 비모 #### [금주 실험 주제🧑🏻‍🔬] **Type** <br/> [WIki URL]() --- # 1주차 토요스터디 / 주제: Optional / (23.04.29) ## 🎁 Optional Unwrapping - If Statements and Forced Unwrapping ```swift if convertedNumber != nil { print("convertedNumber has an integer value of \(convertedNumber!).") } ``` - Optional Binding ```swift if let <#constantName#> = <#someOptional#> { <#statements#> } while let <#constantName#> = <#someOptional#> { <#statements#> } guard let name = person["name"] else { return } ``` - Implicitly Unwrapped Optionals ```swift let assumedString: String! = "An implicitly unwrapped optional string." let implicitString: String = assumedString // no need for an exclamation point ``` - Optional Chaining ```swift class Person { var name: String var job: Job? init(name: String) { self.name = name } } class Job { var jobName: String var pay: Int init(jobName: String) { self.jobName = jobName self.pay = 0 } } let hoon: Person? = Person(name: "hoon") hoon?.job?.pay = 400000 // hoon.job은 nil이므로 실행되지 않음 print(hoon?.job?.pay) // -> nil hoon?.job = Job(jobName: "developer") hoon?.job?.pay = 400000 print(hoon?.job?.pay) // -> Optional(400000) ``` - nil-coalescing operator ```swift var text:String? var output = text ?? "Default value" print(output) // Default value text = "This is a string" output = text ?? "Default String" print(output) // This is a string ``` <br> ## 🔎 실험 1 <details> <summary>예제 코드</summary> <div markdown="1"> ```swift // Optional var productsList: [String?] = ["볼펜", "텀블러", "다이어리", "에코백", "머그컵", "후드집업"] // ! for (index, product) in productsList.enumerated() { if product != nil { print("\(index)번 상품은 \(product!)입니다.") } } // Optional binding: if let for (index, product) in productsList.enumerated() { if let product { print("\(index)번 상품은 \(product)입니다.") } } // Optional binding: guard for (index, product) in productsList.enumerated() { guard let product else { continue } print("\(index)번 상품은 \(product)입니다.") } // Optional pattern matching for (index, product) in productsList.enumerated() { if case let name? = product { print("\(index)번 상품은 \(name)입니다.") } } ``` </div> </details> <br> ## 🔎 실험 2 <details> <summary>예제 코드</summary> <div markdown="1"> ```swift enum productError: Error { case empty(Int) case poor } var budget: Int = 2000 var productsList: [String?] = ["볼펜", "텀블러", "다이어리", "에코백", "머그컵", "후드집업"] //do-catch func buy(productNumber: Int) throws { guard let product = productsList[productNumber] else { throw productError.empty(productNumber) } guard budget >= 1000 else { throw productError.poor } budget -= 1000 print("\(productsList[productNumber]!) 구매, 현재 잔고는 \(budget)") productsList[productNumber] = nil } for index in [1, 2, 2, 3, 5] { do { try buy(productNumber: index) } catch productError.empty(let index) { print("\(index)번 상품이 없습니다.") } catch productError.poor { print("돈이 부족합니다.") } } ``` </div> </details> <details> <summary>예제 코드</summary> <div markdown="1"> ```swift enum productError: Error { case empty(Int) case poor } var budget: Int = 2000 var productsList: [String?] = ["볼펜", "텀블러", "다이어리", "에코백", "머그컵", "후드집업"] //Result Type func buy2(productNumber: Int) -> Result<String, productError> { guard let product = productsList[productNumber] else { return .failure(.empty(productNumber)) } guard budget >= 1000 else { return .failure(.poor) } let productName: String = productsList[productNumber]! budget -= 1000 productsList[productNumber] = nil return .success(productName) } for index in [1, 2, 2, 3, 5] { let a = buy2(productNumber: index) switch a { case .success(let name): print("\(name) 구매") case .failure(let error): print(error) // case .failure(let error(let x)) // print("aaaa", error) } } ``` </div> </details> ## 📚 참조링크 - [🍎Apple Docs: error handling](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/errorhandling) - [🍎Apple Docs: optionalchaining](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/optionalchaining/) - [🍎Apple Docs: Result](https://developer.apple.com/documentation/swift/result) - [📘blog: Result Type](https://velog.io/@un1945/Swift-Result-Type)

    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