23.08.30 수

2023. 9. 1. 21:35·Study/🌱 SeSAC

 

💡 싱글톤 패턴

클래스는 어디서든 인스턴스 생성을 할 수 있다

init이 internal로 선언되어 있기 때문

아무 곳에서나 생성이 되지 않게 하기 위해 private으로 접근 제어 수준을 높이자

Untitled.pngUntitled.png

 

💡 convenience init

searchBar, button 등은 왜 초기화 할 때 frame 지정을 안해줘도 동작이 될까?

Untitled.png

초기화 구문을 구현할 때 convenience를 붙인다면

디폴트 값을 지정해줄 수 있다. 초기화 시 매개변수를 안보이게

내부적으로 디폴트 값이 구현되어 있고, 초기화 시 디폴트 값으로 초기화를 한다.

 

💡 webView

Untitled.pngUntitled.png

 

웹 뷰에서 네비게이션 컨트롤러가 처음에는 투명, 스크롤 하면 불투명

✅ NavigationBar Custom

Untitled.pngUntitled.png

스크롤x  /  스크롤 내렸을 때

navigationController?.navigationBar.standardAppearance = appearance 

Untitled.pngUntitled.png

스크롤x / 스크롤 내렸을 때

 

navigationController?.navigationBar.scrollEdgeAppearance = appearance 

두가지를 다 적용하면 스크롤을 수행할 때와 스크롤이 멈춰있을 때 모두 적용이 된다.

 

→ 네비게이션 바가 웹뷰 화면을 가림

navigationController?.navigationBar.isTranslucent = false 

Untitled.pngUntitled.pngUntitled.png

네비게이션 바를 숨기는 시점과 방식을 지정하는 다양한 방법이 있다

 

✅ 웹 뷰 레이아웃 잡기

웹 뷰를 초기화 후 addSubview를 해야 한다.

Untitled.png

웹 뷰를 addSubview를 하면 런타임 오류가 난다.

Untitled.png

초기화를 해주지 않아서!

var webView = WKWebView() 

 

💡 hitTest

alpha

뷰의 alpha 레벨이 0.01보다 낮으면 뷰의 제스처가 무시가 될 수 있다.

Responder Chain 형식으로 사용자가 클릭한 위치가 어디인지 찾는다.

hittest 기준으로 사용자가 선택한 위치를 찾아 해당 위치가 textfield인지 button인지 찾는다.

 

firstResponder → 클릭하지 않았지만 명시적으로 특정 위치에 반응을 보내준다.

resignResponder → 뷰를 더이상 반응할 필요가 없을 때 responder를 끊어낸다.

 

뷰가 나타날 때 SearchBar에 커서를 시작

searchBar.becomeFirstResponder() 

 

searchBar의 입력 상황이 끝남을 명시

resignFirstResponder()

Untitled.png

→ delegate 연결 필요


💡 URLSession

1. 환경설정

  • shared session
  • default session
  • ephemeral session
  • background session

2. 요청 / 응답 리소스

task

  • data task
  • upload task
  • download task
  • stream task

리소스의 양에 따라 사용

 

 

Untitled.png

resume → 네트워크 통신을 시작하도록 하는 트리거 역할

 

3. response 받는 방법

  • Completion Handler
    • task 다 끝나고 실행, 단 한 번만 실행 됨
  • Session Delegate
    • 최초 응답, 중간 과정 응답
    • progress bar 등 진행률을 다룰 수 있다.
    • 여러 이미지를 한 번에 받을 때 로드 상황을 보고싶을 때

shared session은 completion handler만 사용 가능하다 session delegate로 응답 받는 것이 불가능함

 

✅ session delegate

Untitled.png

configuration 설정 메서드

 

Untitled.png

session delegate를 사용하기 때문에 shared session은 사용 불가!

session = URLSession(configuration: .default, delegate: self, delegateQueue: .main)

 

delegate

session.delegate = self 코드가 매개변수로 들어간다.

⇒ 프로토콜 호출하기

 

session에 URLSession.shared가 들어간다.

Untitled.png

-> completion handler 방식

 

Untitled.png

-> session delegate 방식

➡️ completion handler 방식 보다 session delegate 방식이 코드가 좀 더 간단해진다.

 

 

Untitled.png

요청 방식에 따라 호출할 delegate protocol이 다르다.

 

Untitled.pngUntitled.png

'Study > 🌱 SeSAC' 카테고리의 다른 글

23.09.01 금  (2) 2023.09.01
23.08.31 목  (2) 2023.09.01
23.08.29 화  (0) 2023.08.31
23.08.28 월  (0) 2023.08.31
23.08.25 금  (1) 2023.08.31
'Study/🌱 SeSAC' 카테고리의 다른 글
  • 23.09.01 금
  • 23.08.31 목
  • 23.08.29 화
  • 23.08.28 월
김졀니
김졀니
🍎 iOS 개발
  • 김졀니
    졀니의 개발 공부✨
    김졀니
  • 전체
    오늘
    어제
    • 분류 전체보기
      • iOS
        • Swift
        • UIKit&SwiftUI
        • RxSwift&Combine
        • WWDC
      • Study
        • 🚨 TroubleShooting
        • 🌱 SeSAC
  • 블로그 메뉴

    • 홈
    • Github
  • 인기 글

  • 최근 글

  • 태그

    Drawing Cycle
    인앱리뷰
    Swift
    observable
    RxSwift
    kingfisher header
    mapkit
    displayPriority
    swiftdata
    OperationQueue
    CLLocation
    @PropertyWrapper
    wwdc23
    ios
    layoutIfNeeded
    의존성 주입
    actor
    swift concurrency
    traits
    이미지 캐싱
    FileManager
    위치 권한
    동시성프로그래밍
    mainactor
    Sendable
    concurrency
    clipstobounds
    ReactorKit
    pointfree
    Realm
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
김졀니
23.08.30 수
상단으로

티스토리툴바