목록Swift/CS (14)
HIT해

Redux와 MVVM: 단방향 vs 양방향 데이터 흐름 완전 정리Redux는 주로 React와 같은 프론트엔드 프레임워크에서 사용되는 상태 관리 라이브러리입니다.단방향 데이터 흐름(One-way Data Flow)을 핵심 원칙으로 하며, 상태 관리 로직을 뷰와 명확히 분리해 복잡한 앱에서도 상태를 예측 가능하고 일관성 있게 관리할 수 있도록 도와줍니다.이러한 아키텍처는 React뿐 아니라 Swift 등 다양한 환경에서도 채택되고 있습니다. Flux 패턴Flux는 Facebook이 MVC 패턴의 복잡성과 예측 불가능성을 해결하기 위해 고안한 단방향 데이터 흐름 아키텍처 패턴입니다.Flux는 Action → Dispatcher → Store → View 구조를 가지며, 데이터가 한 방향으로만 흐르도록 설계되..

ifLet 어디서 많이 보지 않았는가 바로 if let 이랑 비슷한 역할을 한다. 주로 상태가 존재하는 경우에만 특정 뷰의 Modifier를 적용하려고 할때 사용된다.상태의 값이 존재할때만 활성화되고 그렇지 않다면 무시된다. 예시 코드를 보자 1. Reducer@Reducerstruct AlertAndConfirmationDialog { @ObservableState struct State: Equatable { @Presents var alert: AlertState? @Presents var confirmationDialog: ConfirmationDialogState? var count = 0 } enum Action { case alert(PresentationActi..
https://developer.apple.com/documentation/swiftui/view/refreshable(action:) refreshable(action:) | Apple Developer DocumentationMarks this view as refreshable.developer.apple.com nonisolatedfunc refreshable(action: @escaping () async -> Void) -> some View 간단하게 새로고침을 구현할 수 있는 키워드다. 새로고침 UI가 상단에 생성되고 안에 정의한 함수들이 실행된다 사용방법struct RefreshableView: View { let store: StoreOf @State var isLoading = fa..
NavigationStack | Apple Developer DocumentationA view that displays a root view and enables you to present additional views over the root view.developer.apple.com NavigationStack 이란?RootView를 표시하고 RootView 위에 추가 뷰를 표시할수 있는 뷰. iOS 16.0 이상에서 동작한다.@MainActor @preconcurrencystruct NavigationStack where Root : View 공식문서상에 적힌 개요를 확인해보자. 1. 기본 네비게이션 스택NavigationStack을 사용하여 뷰의 스택을 루트 뷰 위에 표시한다. 사용자는 Nav..

store.send().finish() vs store.send()store.send():이 코드는 TCA(Typically Composable Architecture)에서 액션을 스토어로 전송한다.기본적으로 이 메서드는 비동기 작업을 시작하고, 해당 액션이 처리되는 동안의 작업을 관리하지 않는다.store.send().finish():finish()는 send(_:) 메서드가 반환하는 Effect의 메서드.finish()는 해당 액션이 완료되었음을 나타내는 신호를 보낸다finish의 역할비동기 작업의 완료 신호:finish()는 비동기 작업이 완료되었음을 나타내는 신호를 보낸다.비동기 효과가 끝났을 때, 상태를 업데이트하거나 후속 작업을 처리하는 데 사용된다.상태 동기화:액션이 완료된 후, 상태가 올바..

defer란?Swift에서 코드 블록의 마지막에 실행될 코드를 예약할때 사용된다.defer 블록내의 코드는 해당 코드 블록이 종료되기 직전에 실행된다. 자원 해제, 상태 복구, 정리 작업과 같이 코드 블록이 끝날 때 반드시 수행되어야하는 작업을 지정하는데 쓰인다. func exampleFunction() { print("Start") defer { print("Deferred: This will run at the end of the function") } print("End")} 실행결과StartEndDeferred: This will run at the end of the function

소스코드 개요더보기이 화면에서는 \를 사용하여 작은 기능을 사용하여 더 큰 기능으로 구성하는 방법을 보여 줍니다리듀서 빌더와 'Scope' 리듀서, 매장의 'Scope' 오퍼레이터.카운터 화면의 도메인을 재사용하여 두 번 더 큰 도메인에 임베딩합니다 전체 코드@Reducerstruct TwoCounters { @ObservableState struct State: Equatable { var counter5 = Counter.State() var counter2 = Counter.State() } enum Action { case counter1(Counter.Action) case counter2(Counter.Action) } var body: some Reducer ..

전체 소스 코드import ComposableArchitectureimport SwiftUIprivate let readMe = """ This screen demonstrates how changes to application state can drive animations. Because the \ `Store` processes actions sent to it synchronously you can typically perform animations in the \ Composable Architecture just as you would in regular SwiftUI. To animate the changes made to state when an action is sent to th..