onReceive
-
SwiftUI - NotificationCenterSwiftUI 2021. 9. 19. 12:06
์๋ ํ์ธ์. ๊ทธ๋ฆฐ์ ๋๋ค๐ข ์ด๋ฒ ํฌ์คํ ์์๋ SwiftUI์์ NotificationCenter๋ฅผ ํ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ํ์ตํ๊ฒ ์ต๋๋ค๐ง๐ปโ๐ป UIKit์์๋ ์ ์๊ฒ ๋๋ฐ ๋์ฒด SwiftUI์์๋ ์ด๋ป๊ฒ ๋ ธํผํฐ์ผ์ด์ ์ผํฐ๋ฅผ ํ์ฉํ ๊น์? ์ ๋ง ์ด๋ฒ ํฌ์คํ ์ ๊ฐ๋จํฉ๋๋ค. ์์๊ฐ์ ์~ํ๊ณ ๋๋๋ฒ๋ฆฌ๋ ๋ ํฌ๊ฒ ๋จ๊ณ ๋ณด์ ์ผ ๋ฉ๋๋ค๐ ์, ์ฐธ๊ณ ๋ก ์ด์ ์ ํฌ์คํ ํ๋ ์คํฌ๋ฆฐ์ท ์บก์ณ/๋ นํ ๊ฐ์ง ๋ฐ ๋ฐฉ์ง์ ๋ํด UIKit์ผ๋ก ๊ตฌํํ๊ฑธ SwiftUI์ NotificationCenter๋ฅผ ํตํด ๊ตฌํํ๋ ์์ ๋ก ๋ณด๊ฒ ์ต๋๋ค๐๐ป NotificationCenter ์์ฑ import SWiftUI struct mainView: View { let screenCapturePublisher = NotificationCenter.defaul..