사과
  • 애플 개발자 문서 한글 번역
  • App Frameworks
    • Foundation
      • 숫자, 데이터와 기본값
      • 문자열과 텍스트
      • 컬렉션
      • 날짜와 시간
      • 데이터 포맷
      • 작업 관리
        • Operation
        • OperationQueue
        • Timer
      • 리소스
        • Bundle
      • 파일 시스템
        • FileManager
      • Notification
        • NSKeyValueObserving
      • URL 로딩 시스템
        • 웹사이트 데이터를 메모리에 저장하기
        • URLSession
          • URLSessionConfiguration
            • urlCache
            • requestCachePolicy
          • configuration
        • URLSessionTask
        • URLRequest
        • URLResponse
        • HTTPURLResponse
        • 캐시 데이터에 접근하기
        • CachedURLResponse
        • URLCache
      • Object Runtime
        • NSValue
    • UIKit
      • UIKit으로 앱 개발
      • 앱과 환경
        • 앱 라이프 사이클 관리하기
        • 앱 실행에 대응하기
        • UIApplication
      • 문서, 데이터와 클립보드
      • Mac Catalyst
        • iPad 앱을 Mac 버전으로 만들기
        • 아이패드 앱의 맥 최적화
      • 뷰와 컨트롤
        • UIView
        • Table Views
          • UITableView
          • UITableViewCell
          • UIRefreshControl
        • UIScrollView
      • View Controllers
        • UIViewController
        • UITableViewController
        • UISearchController
      • 애니메이션과 햅틱
        • 프로퍼티 기반 애니메이션
          • UIViewPropertyAnimator
        • View controller 전환
      • 터치, 누르기, 제스처
        • UIResponder
        • UIKit 제스처 처리
        • 다중 제스처 인식기 조정
        • UILongPressGestureRecognizer
        • UIPanGestureRecognizer
          • maximumNumberOfTouches
          • minimunNumberOfTouches
          • translation(in:)
          • setTranslation(_:in:)
          • velocity(in:)
        • UIGestureRecognizer
    • Swift
      • 스위프트 표준 라이브러리
        • 메모리 직접 관리
          • 포인터 파라미터를 사용하는 함수 호출
          • UnsafePointer
          • UnsafeMutableRawBufferPointer
    • SwiftUI
      • 뷰와 컨트롤
        • View
        • Text
        • TextField
      • 뷰 레이아웃과 표현
      • 그리기와 애니메이션
      • 프레임워크 통합
      • 상태와 데이터 흐름
  • Graphics and Games
    • Core Animation
      • CALayer
      • CAAction
      • CAShapeLayer
      • CADisplayLink
    • Core Graphics
      • CGFloat
      • CGPath
  • App Services
    • Combine
    • WebKit
      • WKWebView
  • Media
    • AVFoundation
      • 시스템 오디오 상호작용
        • AVAudioSession
          • AVAudioSession.Category
            • ambient
            • multiRoute
            • playAndRecord
            • playback
            • record
            • soloAmbient
          • AVAudioSession.Mode
      • AVFoundation 자료형
  • Documentation Archive
    • 번들 프로그래밍 가이드
      • 번들에 대해
      • 번들 구조
    • Key-Value Observing 프로그래밍 가이드
    • Threading 프로그래밍 가이드
      • About Threaded Programming
      • Thread Management
  • ETC
    • Not Found
Powered by GitBook
On this page
  • 개요
  • 주제
  • 변경 노티피케이션
  • Observer 등록
  • Notifying Observers of Changes
  • Observing Customization
  • 상수
  • 같이 보기
  • 관련 문서
  1. App Frameworks
  2. Foundation
  3. Notification

NSKeyValueObserving

다른 객체의 특정 속성의 변경이 있을 때 알림을 받기 위해서 객체가 채택하는 비공식적인 프로토콜

PreviousNotificationNextURL 로딩 시스템

Last updated 5 years ago

원문 출처

개요

옵저버는 객체의 단순 속성과, 일대일 관계, 일대 다 관계를 포함한 객체의 모든 프로퍼티를 관찰할 수 있게 해줍니다. 일대 다 관계의 Observer는 변경 유형뿐만 아니라 변경과 관련된 객체에 대해서도 통지를 받습니다.

는 KeyValueObserving 프로토콜의 구현을 제공함으로써 모든 객체에 자동 관찰 기능을 추가합니다. 자동 관찰 기능을 비활성화시킨 다음 이 프로토콜의 메서드를 사용하여 더 개선된 notification을 수동으로 구현할 수 있습니다.

주제

변경 노티피케이션

  • func observeValue(forKeyPath: String?, of: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) 관찰 대상 객체에 대한 특정 key path의 값이 변경된 경우 Observer 객체에게 통보합니다.

Observer 등록

  • func addObserver(NSObject, forKeyPath: String, options: NSKeyValueObservingOptions = [], context: UnsafeMutableRawPointer?) Observer 객체로 등록해서 이 메세지를 수신하는 객체와 관련된 key path에 대한 KVO notification을 받도록 합니다.

  • func removeObserver(NSObject, forKeyPath: String)

    Observer 객체가 특정 key path와 관련된 변경 메세지를 더 이상 받지 않도록 합니다.

  • func removeObserver(NSObject, forKeyPath: String, context: UnsafeMutableRawPointer?)

    주어진 context 하에서 Observer 객체가 특정 key path와 관련된 변경 메세지를 더 이상 받지 않도록 합니다. (역자 주: context의 역할에 대한 )

Notifying Observers of Changes

  • func willChangeValue(forKey: String) Observer 객체에게 forKey: 에 해당하는 프로퍼티가 곧 변경될 것임을 알립니다.

  • func didChangeValue(forKey: String)

    Observer 객체에게 forKey: 에 해당하는 프로퍼티가 방금 변경되었음을 알립니다.

  • func willChange(NSKeyValueChange, valuesAt: IndexSet, forKey: String)

    Informs the observed object that the specified change is about to be executed at given indexes for a specified ordered to-many relationship.

  • func didChange(NSKeyValueChange, valuesAt: IndexSet, forKey: String) Informs the observed object that the specified change has occurred on the indexes for a specified ordered to-many relationship.

  • func willChangeValue(forKey: String, withSetMutation: NSKeyValueSetMutationKind, using: Set)

    Informs the observed object that the specified change is about to be made to a specified unordered to-many relationship.

  • func didChangeValue(forKey: String, withSetMutation: NSKeyValueSetMutationKind, using: Set)

    Informs the observed object that the specified change was made to a specified unordered to-many relationship.

Observing Customization

  • class func automaticallyNotifiesObservers(forKey: String) -> Bool

    Observer 객체가 forKey: 를 자동 key-value observing(KVO) 하고 있다면 true를 반환합니다.

  • class func keyPathsForValuesAffectingValue(forKey: String) -> Set

    Returns a set of key paths for properties whose values affect the value of the specified key.

  • protocol NSKeyValueObservingCustomization

  • var observationInfo: UnsafeMutableRawPointer?

    Returns a pointer that identifies information about all of the observers that are registered with the observed object.

상수

  • class NSKeyValueObservation

  • struct NSKeyValueObservedChange

  • enum NSKeyValueChange 관찰 가능한 변경 유형들

  • struct NSKeyValueObservingOptions The values that can be returned in a change dictionary.

  • struct NSKeyValueChangeKey

    The keys that can appear in the change dictionary.

  • enum NSKeyValueSetMutationKind

    The kinds of mutation that you can make to an unordered collection.

같이 보기

관련 문서

https://developer.apple.com/documentation/foundation/notifications/nskeyvalueobserving
NSObject
stackoverflow의 설명
Key - Value Observing 프로그래밍 가이드