TIL100 ✨

YaR Lab·2023년 9월 8일
0

TIL✨

목록 보기
86/135
post-thumbnail

🗓️23.09.08

백 번째 틸 입니다!!!!

https://developer.apple.com/documentation/uikit/uiscenedelegate/3197917-scenedidenterbackground

Notification Center

import Foundation

class Teacher {
    func callStudent() {
        let noti = Notification(name: Notification.Name.hey)
        NotificationCenter.default.post(noti)
    }
}

class Student {
    let name: String
    
    init(name: String) {
        self.name = name
        NotificationCenter.default.addObserver(self,
                                               selector: #selector(answerToTeacher(noti:)),
                                               name: Notification.Name.hey, object: nil)
    }
    
    @objc func answerToTeacher(noti: Notification) {
        print("Ok Teacher I'm coming. My name is \(name)")
    }
}

extension Notification.Name {
    static let hey = Notification.Name("hey")
}

원래는 다음과 같이 노티피케이션을 사용해야하지만
uikit 자체 객체에서 상태변화가 있을때 자동으로 post해주는 노티피케이션을 사용할 수도 있다.

https://welly-log.tistory.com/36

completion

https://developer.apple.com/documentation/uikit/uiview/1622515-animate

https://developer.apple.com/documentation/uikit/uicontextualaction

0개의 댓글