Skip to content

Example application based on SwiftMVI & SwiftUseCase

Notifications You must be signed in to change notification settings

xtro/SwiftMVI-Examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

SwiftMVI-Examples

Example application based on SwiftMVI & SwiftUseCase

import Foundation
import SwiftMVI
import SwiftUI

typealias AsyncFeature = Observer & Processing & ImmutableState & AsyncIntentReducer

class AssetsFeature: AsyncFeature {
    enum State {
        case loading
        case assets([AssetItemData])
        case failed(Error)
    }
    var state = .loading
    
    enum Intent {
        case fetch
    }
    
    func reduce(intent: Intent) async {
        switch intent {
        case .fetch:
            await state { _ in
                .loading
            }
            do {
                let assets = try await run(Network.getAssets).data
                await state { _ in
                    .assets(assets)
                }
            }catch{
                await state { _ in
                    .failed(error)
                }
            }
        }
    }
}

About

Example application based on SwiftMVI & SwiftUseCase

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages