BLU
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    # 날씨 앱 [STEP 2-1] Blu, Jenna >안녕하세요! 코리(@corykim0829)🐶! 🌙**TEAM LuNna**🌙 의 Blu, Jenna입니다! > >이번 STEP 2는 2단계로 나누어 진행하기로 하였습니다! >2-1에서는 현재 위치의 위도와 경도를 알아내는 로직 및 이를 바탕으로 API를 통해 데이터를 요청하고 받아오는 기능 구현을 진행하였고, >2-2에서는 위도와 경도를 주소로 변환하는 로직 구현 및 HTTP GET 명시적 호출을 구현할 예정입니다. > >리뷰 잘 부탁드립니다. 주말 잘 보내세요! 감사합니다! 🙇🏻🙇🏻 <br> # 🧑🏼‍💻 작업 목록 ## 현재 위치의 위도와 경도 구하기 - [x] 시뮬레이터의 위도와 경도를 Custom으로 설정 - Features > Location > Custom Location 탭을 통해 현재 위치(용산)의 좌표를 임의로 지정 ![좌표지정 스크린샷](https://user-images.githubusercontent.com/71758542/226542299-41be22be-20fe-45cc-a1b0-73cc33cc9ee2.png) - [x] CoreLocation을 통해 현재 좌표 가져오기 ![현재좌표 출력 스크린샷](https://user-images.githubusercontent.com/71758542/226542769-eeaaad5c-6a60-4d34-83b4-3aca1d799602.png) - [x] CoreLocation과 API를 통해 현재 좌표의 날씨 Data 가져오기 ```swift Task { let customLocationCurrentWeather = try await WeatherParser<CurrentWeatherComponents>.parse(at: coordinate) let customLocationForecastWeather = try await WeatherParser<ForecastWeatherComponents>.parse(at: coordinate) print(customLocationCurrentWeather) print(customLocationForecastWeather) >} ``` >저희의 현재 코드에서는 `print()`를 삭제하였고, 프로퍼티가 사용되지 않음에 따라 각 프로퍼티명을 언더바 `_`로 대체해 두었습니다! ![현재좌표 기반 API호출 스크린샷](https://user-images.githubusercontent.com/71758542/226540685-3f7ace08-541c-494d-8c65-52125e0a3434.png) <br> # 📚 학습 키워드 및 학습 내용 ## 1. CoreLocation > 🖇️ 참고한 공식문서: > - [CoreLocation](https://developer.apple.com/documentation/corelocation) > - [CLLocationManager](https://developer.apple.com/documentation/corelocation/cllocationmanager) > - [CLLocationManagerDelegate](https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate) - **학습 내용** - Core Location을 사용하기 위해서는 `CoreLocation` 프레임워크를 import해야 함 - Core Location은 장치의 지리적 위치와 방향을 얻는 것으로 `CLLocationManager` 클래스의 인스턴스로 Core Location 서비스를 구성하고 사용하고 중지시킬 수 있음 - Core Location으로 알 수 있는 정보 - 위치 업데이트 - 지역 모니터링 - iBeacon 감지 및 찾기 - 나침반의 방향 - Core Location을 사용하기 위해서는 승인을 요청해야 함 - 승인 변경을 비롯한 이벤트는 `CLLocationManagerDelegate` 프로토콜을 준수하는 개체에서 수신 - `CLLocationManager` 인스턴스가 할당되면 시스템이 delegate의 `locationManagerDidChangeAuthorization(_:)`메서드에 앱의 승인 상태를 보고함 - 그렇기 때문에 manager가 구성되는 시점에 delegate를 즉시 할당해야 함 - 위치 서비스 권한 - When In Use와 Always가 있음 - 공식문서에서는 가능하면 When In Use만 사용하는 것을 권장 - 위치 정보는 민감한 개인정보이기 때문에 사용자에게 위치 사용에 대한 설명이 필요함 - **적용 과정** - 시뮬레이터에 커스텀으로 설정해 둔 현재 위치 받아오기 - **문제와 해결** |문제와 해결|내용| |:---:|:---| |문제|ViewController의 `viewDidLoad()` 메서드 내부에 `locationManager.requestLocation()`를 호출하는 경우 `locationManager(didFailWithError:)`가 호출되던 문제| |해결|학습 내용처럼 CLLocationManager 할당 시 권한을 확인하는 메서드가 호출되므로, 사용자에게 권한 요청을 하기 전에 위치 정보를 요청하게 됨! 이로 인해 location을 받아올 수 없어서 error handling 관련 메서드가 호출됨!<br>**⭐️권한을 확인하는 메서드 내부에서만 location을 호출하도록 리팩토링**| - **아쉬운 점** 전력 사용을 최적화 할 수 있는 설정에 대한 학습을 추가로 진행하지 못해서 아쉬웠지만, STEP 2-2에서 함께 학습 후 반영하기로 함! ## 2. URLComponent > 🖇️ 참고한 공식문서: > - [URLComponent](https://developer.apple.com/documentation/foundation/urlcomponents) > - [URLQueryItem](https://developer.apple.com/documentation/foundation/urlqueryitem) - **학습 내용** - `URLComponents` 인스턴스는 `URL?`타입 프로퍼티를 가짐 - `URLQueryItem`은 key, value 형태로 생성 - `path`속성에 String을 append, `queryItems`에 [`URLQueryItem`]을 할당 혹은 append해주면 자동으로 url에 알맞은 양식으로 추가됨 - **적용 과정** - 아래 이유로 URLComponents를 사용하도록 리펙토링에 도전 1. 기존에 비해 문자열 관련 연산을 줄이고 기본제공 타입을 활용하고자 함, 2. URL의 구성요소에 보다 구조적으로 접근하고 활용할 수 있겠다는 장점을 고려 - 적용 방법 1. `baseURL`을 기반으로 URLComponents 인스턴스를 만들어 필요한 `path`, `query` 매개변수들을 추가·할당 2. 완성된 인스턴스의 url을 옵셔널바인딩하여 에러를 던지거나 url(`URL`타입)을 반환 - **문제와 해결** |문제와 해결|내용| |:---:|:---| |기존|URLComponents인스턴스를 static 프로퍼티로 선언, path는 `해당 인스턴스.path.append("String")`해주는 식으로 구현| |문제|static 프로퍼티다 보니, `WeatherParser.make(at:weatherRange:)` 메서드가 호출될 때마다 path가 바뀌지 않고 덧붙여지는(append) 문제| |해결| static 프로퍼티로는 URLComponents 생성자에 필요한 `baseURL`(String) 형태만 저장, 메서드 body 내에서 URLComponents 인스턴스를 생성하여 쓰도록 수정| <br> # 🙋🏻 질문 거리 ## 1. iOS Deployment target 관련 처음 fork 받은 상태의 프로젝트는 버전이 12.0이었습니다. Core Location을 사용하기 위해 CLLocationManager 인스턴스를 할당한 후 이에 필요한 메서드인 `locationManagerDidChangeAuthorization(_:)`를 구현하는 과정에서 14.0 버전 이상에서 작동하도록 수정해야 한다는 에러 메세지를 발견하였습니다. 카카오톡의 앱스토어상 호환성 탭을 확인해 본 결과 iOS 14.0 이상 필요로 되어있어서 저희 앱 또한 14.0 버전 이상에서 가능한 기능을 구분하는 코드를 작성하는 것보다 프로젝트의 최소 iOS Deployment target을 14.0으로 변경하였습니다. 혹시 프로젝트에서 처음 제공된 iOS Deployment target을 사용하고, 14.0이상에서만 작동하는 (available)코드를 작성해야 하는 것인지, 아니면 저희처럼 **임의로 iOS Deployment target을 높여도 되는지 궁금합니다!**

    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