๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŽ iOS/iOS

[iOS] NotificationCenter ๋™์‹œ์— ๋‹ค๋ฅธ ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ ๊ด€๋ฆฌํ•˜๊ธฐ

by Fomagran ๐Ÿ’ป 2019. 12. 14.
728x90
๋ฐ˜์‘ํ˜•

์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋‹ค ๋ณด๋ฉด ํŠน์ • ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ์—์„œ ์–ด๋–ค ํ–‰๋™์„ ํ–ˆ์„ ์‹œ ๋™์‹œ์— ๋‹ค๋ฅธ ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ๋ณ€ํ™”ํ•˜๊ฒŒ ํ•˜๊ณ ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์€๋ฐ ์ด ๋•Œ ์œ ์šฉํ•œ๊ฒŒ ๋ฐ”๋กœ NotificationCenter์ด๋‹ค.

 

๊ฐ’์„ ๋ณด๋‚ด์•ผํ•  ํด๋ž˜์Šค์—์„œ ๋…ธํ‹ฐํ”ผ์ผ€์ด์…˜ ์ด๋ฆ„์„ ์ •ํ•ด์ฃผ๊ณ 

 NotificationCenter.default.post(name: NSNotification.Name("Notification"), object: nil)

๊ฐ’์„ ๋ฐ›์•„์•ผํ•  ํด๋ž˜์Šค์— ์—๋“œ์˜ต์ €๋ฒ„๋ฅผ ์ ์–ด์ฃผ๊ณ  ์›ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰์‹œํ‚ฌ ์…€๋ ‰ํ„ฐ๋ฅผ ์ ์–ด์ค€ ๋‹ค์Œ ๊ฐ’์„ ๋ณด๋ƒˆ๋˜ ๋…ธํ‹ฐํ”ผ์ผ€์ด์…˜ ์ด๋ฆ„์„ ์ ์–ด์ค€๋‹ค,

   NotificationCenter.default.addObserver(self, selector: #selector(SearchExchangeTag.notifiactionFired(_:)), name: NSNotification.Name("Notification"), object: nil)

์•„๋ž˜๋Š” ์˜ค๋ธŒ์ ํŠธ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋…ธํ‹ฐํ”ผ์ผ€์ด์…˜์„ ๋ฐ›์•˜์„ ๋•Œ ์‹คํ–‰์‹œํ‚ฌ ์ฝ”๋“œ๋ฅผ ์ ์–ด์ค€๋‹ค.

 @objc func notifiactionFired(_ notification:Notification) {
        
        //์‹คํ–‰์‹œํ‚ฌ ์ฝ”๋“œ
        

        }

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€