Hemg2
    • 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
    • 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 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
    # 노티피케이션 - 방송을 한다 95.8fm 채널 count -> 1로 변경하겠습니다 하면 95.8fm 채널 이용자들의 count 가 변경되는? 방송실에서 알렸으니 이걸 변경을 진행한다~ 이런 느낌적인 느낌 - Notification(채널?)을 발송하면 NotificationCenter(방송국!)에서 메세지를 전달한 observer를 처리할 때까지 대기한다. - 즉, 흐름이 동기적으로 흘러간다. - NotificationCenter(방송국!)를 통해서 어떠한 화면에서 다른 화면으로 데이터를 전달 할 수 있다. - NotificationCenter은 언제 사용할까? - 앱 내에서 공식적인 연결이 없는 두개 이상의 컴포넌트들의 상호작용이 필요할때 사용한다. - 상호작용이 반복적으로 그리고 지속적으로 이루어져야 할때 - 하나의 변경을 사항을 여러곳에 보내야할때 ### 처음 화면(보내는 화면) ```swift func firstPost() { NotificationCenter.default.post(name: Notification.Name(rawValue: "1"), object: self.nameLabel.text) } ``` ```swift func secondPost() { NotificationCenter.default.post(name: Notification.Name(rawValue: "2"), object: self.phoneNumberLabel.text) } ``` - Post - Post는 객체가 NotificationCenter로 이벤트를 보내는 행위를 의미합니다. ```swift @IBAction func pushView(_ sender: UIButton) { let secondView = SecondViewController() self.navigationController?.present(secondView, animated: true) firstPost() secondPost() } ``` - 노티를 던진다? 버튼을 누르면서 화면 이동을 진행할때에 노티를 던져 줘야지만 넘어가게 된다. ### 두번째 화면(받는 화면) ```swift override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemBackground addObserverFirst() addObserverSecond() } Observer 등록 진행 func addObserverFirst() { NotificationCenter.default.addObserver(forName: Notification.Name("1"), object: nil, queue: nil) { [weak self] notification in if let test = notification.object as? String { self?.titleLabel.text = test } } } func addObserverSecond() { NotificationCenter.default.addObserver(forName: Notification.Name("2"), object: nil, queue: nil) { [weak self] notification in if let test = notification.object as? String { self?.subTitleLabel.text = test } } } ``` ### 노티피케이션 제거하기 - Observer 제거하기 노티를 제거하지않으면 메모리에 계속 올라가 있게 되므로 변경이 되었다면 후에 해제를 해줘야한다. ```swift deinit { NotificationCenter.default.removeObserver(self) } ``` - 저의 경우에는 다이어리프로젝트때 사용을 해봤습니다. ```swift private func setUpNotification() deinit { NotificationCenter.default.removeObserver(self) } ``` - 리뷰어의 피드백! ![image](https://hackmd.io/_uploads/rkXA7oQEa.png) #### 전체적인 주의 사항 - 노티피케이션 사용 시 강한 참조 주의: 노티피케이션을 사용할 때, Observer의 클로저가 실행될 때 강한 참조가 발생할 수 있습니다. 그렇기에 [weak self] 사용하여 강한 참조 순환을 피하는 것이 중요합니다. - 노티피케이션의 전역 사용에 주의: 노티피케이션은 전역 이벤트를 처리하는 데 사용되므로 다중으로 사용하면 코드의 가독성이 감소하고 디버깅이 어려워집니다. 필요한 경우에만 사용하고, 사용시에 다른 방법이 더 적절한지 고려하는 것이 좋습니다. - ViewController에서의 Observer 제거: 노티피케이션 Observer를 등록한 ViewController가 화면에서 제거될 때, 해당 Observer를 제거하지 않으면 메모리 누수가 발생할 수 있습니다. viewWillDisappear에서도 해당 Observer를 제거하여 안전성을 높이는 것이 좋습니다.

    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