목차
- SwiftUI란?
- App Protocol
- View Protocol
1. SwiftUI란?
Declare the user interface and behavior for your app on every platform.
모든 플랫폼에서 사용자 인터페이스 및 동작을 선언합니다.

오,, UIKit과 마찬가지로
앱의 UI / UX 할 수 있게 도와주는 기술입니다.
SwiftUI provides views, controls, and layout structures for declaring your app’s user interface. The framework provides event handlers for delivering taps, gestures, and other types of input to your app, and tools to manage the flow of data from your app’s models down to the views and controls that users see and interact with.
SwiftUI는 앱의 사용자 인터페이스 선언을 위해 views, controls, and layout structures를 제공합니다.
이 프레임워크는 탭, 제스처 및 기타 유형의 입력을 앱에 전달하기 위한 이벤트 핸들러와 앱 모델에서 사용자가 보고 상호 작용하는 보기 및 컨트롤에 이르기까지 데이터 흐름을 관리하는 도구를 제공합니다.
UIKit도 UI를 쉽게 그릴 수 있게
UIButton이나 UILabel가 제공됐었는데
SwiftUI도 UIKit처럼 그런 요소들을 제공한다고 합니다.
Define your app structure using the App protocol, and populate it with scenes that contain the views that make up your app’s user interface. Create your own custom views that conform to the View protocol, and compose them with SwiftUI views for displaying text, images, and custom shapes using stacks, lists, and more. Apply powerful modifiers to built-in views and your own views to customize their rendering and interactivity. Share code between apps on multiple platforms with views and controls that adapt to their context and presentation.
App 프로토콜을 사용하여 앱 구조를 정의하고 앱의 사용자 인터페이스를 구성하는 보기가 포함된 장면으로 채웁니다. View 프로토콜을 준수하는 고유한 사용자 정의 보기를 생성하고 스택, 목록 등을 사용하여 텍스트, 이미지 및 사용자 정의 모양을 표시하기 위해 SwiftUI 보기로 구성합니다. 내장된 뷰와 자신의 뷰에 강력한 수정자를 적용하여 렌더링 및 상호 작용을 사용자 지정합니다. 컨텍스트 및 프레젠테이션에 적응하는 보기 및 컨트롤을 사용하여 여러 플랫폼의 앱 간에 코드를 공유합니다.
App 프로토콜을 채택해서 앱 구조를 정의하고
View 프로토콜을 채택해서 사용자 정의 view를 만들고
text, images, stacks, list 등을 만들기도 한대요.
이 프로토콜들에 대해서 좀 더 자세히 볼게요.
2. App Protocol
앱의 구조 및 동작을 나타내는 타입
SwiftUI는 iOS13+ 인데 이건 iOS 14+
???
궁금해서 SwiftUI 프로젝트 만들어서 iOS 13으로 낮춰봤습니다.

main(), Scene, Window가 뭐 하는 애들인데 안되냐고!
main
앱을 초기화하고 실행합니다.
Precede the structure’s declaration with the @main attribute to indicate that your custom App protocol conformer provides the entry point into your app. The protocol provides a default implementation of the main() method that the system calls to launch your app. You can have exactly one entry point among all of your app’s files.
@main을 붙이면 앱을 시작하기 위해 호출하는 main() 기본 구현을 제공합니다.
즉, @main을 붙이면 앱의 진입점이라는 것!
WindowGroup
동일하게 구성된 windows 그룹을 나타내는 하나의 화면입니다.
Use a WindowGroup as a container for a view hierarchy that your app presents. The hierarchy that you declare as the group’s content serves as a template for each window that the app creates from that group:
SwiftUI takes care of certain platform-specific behaviors. For example, on platforms that support it, like macOS and iPadOS, people can open more than one window from the group simultaneously. In macOS, people can gather open windows together in a tabbed interface. Also in macOS, window groups automatically provide commands for standard window management.
iOS 13+ 부터 멀티 윈도우가 가능해지면서 UIKit에서는 window들을 관리하기 위해 UIWindowScene이 생겼었습니다.
SwiftUI에는 윈도우들을 관리하기 위해 WindowGroup이 있습니다.
iPadOS나 MacOS는 멀티 윈도우가 가능하기 때문에 만약 멀티 윈도우를 지원하는 앱을 만든다면 이것을 더 공부해 보면 될 듯합니다!
Scene
시스템에서 관리하는 수명 주기가 있는 앱 사용자 인터페이스의 일부입니다.
A scene acts as a container for a view hierarchy that you want to display to the user.
Read the scenePhase environment value from within a scene or one of its views to check whether a scene is active or in some other state.
뷰계층의 컨테이너 역할을 하고 scene이 활성상태인지 아니면 다른 상태인지 scenePhase 환경 값을 읽는다고 합니다.
View Protocol
앱 사용자 인터페이스의 일부를 나타내고 보기를 구성하는 데 사용하는 modifiers를 제공하는 유형입니다.
modifier란?
이렇게 SwiftUI에서는 Text("Hamlet")에 폰트를 바꾸고 싶으면 .font(.title)라는 것을 붙여주는데
공식 문서에서 .font(_:)를 modifier라고 부르고 있습니다.
font(_:)를 사용하고 나면 새로운 View Type이 반환됩니다~!
느낀 점
앱 개발을 처음 시작할 때 AppDelegate 파일을 보면서 이게 뭐지.. 이랬었는데
SwiftUI 프로젝트에는 AppDelegate도 없고 SceneDelegate도 없어서 진입장벽이 낮아진 느낌이랄까? 암튼!
점점 쉬워지는 것 같아서 너무 좋네요!!
근데 일단 백문이 불여일타
튜토리얼로 공식문서도 훑어봤으니 튜토리얼로 맛 한번 보고 오겠습니다!

'IOS Swift' 카테고리의 다른 글
[Swift] Protocol - 프로토콜이란? (0) | 2023.10.10 |
---|---|
[iOS] imageView 이미지 크기대로 동적 사이즈 변경 (0) | 2023.10.06 |
IBDesignable, IBInspectable 알아보기 (2) | 2023.07.16 |
Xcode Cloud (2) - Work flow (0) | 2023.07.02 |
Xcode cloud (1) - Setting (0) | 2023.06.04 |