✔︎ 오늘의 정리
- cocoa touch Framework (iOS Framework)
- App Lifecycle / AppDelegate Scene
- version: @available / Button(configration) / date picker
- View: hidden(스택뷰) alpha, opacity(기존 뷰안의 뷰 차이)
- action Any
- DateFormatter
- 실기기 빌드
✔︎ iOS Framework

✔︎ AppLifeCycle
App의 LifeCycle은 iOS 13 이전과 이후로 나뉜다.
먼저, iOS 13 이전은 AppDelegate 하나였는데, 이 친구가 앱의 생명 주기(실행 / 종료)와 UI 라이프 사이클(background)를 모두 관리했다. 하지만, iOS 13 이후로 SceneDelegate가 나오면서 앱 실행 / 제거 관리만 AppDelegate가 하고 LifeCycle 관련해서는 SceneDelegate가 하게 되었다.
App의 LifeCycle은 크게 보면 Not Running / Foreground / Background / Suspend 네 가지로 나눌 수 있다.
- Not Running
말 그대로 앱이 시작되기 전 상태이다.
- Foreground
Foreground의 경우에는 Active와 inActive로 나뉠 수 있다.
Active는 앱이 화면에서 실행 중인 상태로, iOS 13 이전까지는 한 번에 하나의 앱만 실행 가능했다.
Inactive의 경우에는 Active의 반대로, 앱이 화면에서 실행 중이나 어떤 신호도 받지 않는 상태를 말한다.
참고. 전화는 iOS 13 이전에는 Active 상태였다가 iOS 13 이후로 InActive 상태로 넘어갔다!
- Background
앱이 화면에는 보이지만 코드는 실행되고 있는 상태를 말한다.
Background에서 여전히 실행되고 있는 앱과 종료되는 앱이 있는데, 이를 확인하려면 홈 버튼을 길게 눌렀다가 다시 들어갔을 때, 런치 스크린이 보이는 것은 Background에서 종료된 앱이고, 이전에 실행되던 화면이 여전히 실행된다면 종료되지 않은 앱이다.
- suspend
앱이 끝나기 직전 상태를 말한다.

이전에 AppDelegate에서는 위와 같이 App의 LifeCycle을 분류하고, application어쩌구라는 코드를 이용해서 관리했는데, iOS 13 이후, 아이패드 기반으로 iOS가 바뀌면서 큰 변화가 일어났다.
앞서 말했듯 SceneDelegate의 등장이다.
아이패드 사용 시, 하나의 프로세스에서 두 개의 Scene을 사용할 수 있게 되었기 때문에 SceneDelegate가 나왔다.
- AppDelegate
- Process Lifecycle
- AppLaunched
- AppTerminated
- SceneDelegate
- UI 라이프 사이클(background) 관리
- EnteredForeground
- BecomeActive
SceneDelegate에서 Scene이 새롭게 생성되고 종료되는 트리거를 AppDelegate에게 알려줌으로써, AppDelegate가 앱의 생성과 종료 시점을 통제하게 된다.
아래는 SceneDelegate의 코드이다. 살펴보면 UI LifeCycle을 관리하고 있는 걸 확인할 수 있다.
// 앱이 종료
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
}
// 백그라운드에 있다가 다시 가지고 오면!
// background에 갔을 때? 나갔을 때도 나옴
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
print("sceneDidBecomeActive")
}
// Active -> background
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
print("sceneWillResignActive")
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
print(#function)
}
// 종료되어 background로 갔을 때
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
print(#function, "영상", "음악")
// 영상이나 음악을 다운받고 있다가 백그라운드에 나갔을 때도 다운이 되는 경우
// 이쪽을 건드려준 거임
}
✔︎ version: @available / Button(configration) / date picker
우리는 더 많은 사용자를 위해서 많은 버전을 지원하는 것이 좋다.
하지만, 문제가 있으니... ...
바로 버전마다 업데이트되는 기능들은 이전의 버전에서는 사용할 수 없다는 것이다.
따라서, 우리는 분기 처리를 통해 기능을 나누어 주어야 한다.
각각의 Class에
@available (iOS 14.0, *)
이런 식으로 써 준다면 분기 처리를 할 수 있다.
해당 클래스나 구조체를 iOS14 버전 이상부터 적용하겠다는 뜻이다.
근데 분기처리라고 하지 않았나?!
흠. 분기처리는 #available
keyword로 할 수 있다.
if #available (iOS 14.0, *) {
// iOS 14.0 버전 이상일 경우 작동
} else {
// 미만인 경우에 작동
}
✔︎ hidden(스택뷰) alpha, opacity(기존 뷰안의 뷰 차이)
- Hidden
- StackView X ) 자기 자리를 차지하면서 없어짐
- StackView O ) 자기 자리를 차지하지 않고 옆 친구를 당겨줌!

- Alpha & Opacity
- 알파는 하위 뷰가 모두 투명해짐
- 반면, opacity의 경우에는 해당 뷰만 투명해진다.


나머지는 코드로 작성했으니 생략해도 괜찮을 것 같다. 굿!
'TIL' 카테고리의 다른 글
[SeSAC] August 1, 2023 (0) | 2023.08.01 |
---|---|
[SeSAC] July 31, 2023 (0) | 2023.08.01 |
[SeSAC] July 27, 2023 (0) | 2023.07.28 |
[SeSAC] July 24, 2023 (0) | 2023.07.24 |
[SeSAC] July 23, 2023 (2) | 2023.07.23 |