티스토리 뷰

728x90
반응형

notification 이 프로젝트 내에서 퍼져있기 때문에 이름이 가끔 겹치기도 하고 내가 무슨 이름을 사용했는지 기억이 안나기도 했다.

그래서 extension 으로 Notification.Name 을 확장시켜서 사용해보기로 했다.

  • NotificaationName+Extention
extension Notification.Name {

    static let testNotification = Notification.Name(rawValue: "test")
}
  • 사용할 때
// post
NotificationCenter.default.post(name: .testNotification, object: nil)

// observer
NotificationCenter.default.addObserver(self, selector: #selector(testMethod), name: .testNotification, object: nil)

출처 :

[iOS] NotificationCenter 깔끔하게 쓰기

728x90
반응형
댓글
최근에 올라온 글
최근에 달린 댓글
글 보관함
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
링크
Total
Today
Yesterday