Call Amplify.configure() before using any methods on the category. | SwiftUI

Call Amplify.configure() before using any methods on the category. | SwiftUI


0

When I start my project I got this error. How can I fix this problem. I am trying to use Graphql without Apollo SDK.

Error:

Failed to initialize Amplify with ConfigurationError: AWSS3StoragePlugin.AWSS3StoragePlugin cannot be added after Amplify.configure().
Recovery suggestion: Do not add plugins after calling Amplify.configure().
/Users/ufukkosker/Library/Developer/Xcode/DerivedData/ArtApp-xxxxxxxhzyxxxxx/SourcePackages/checkouts/amplify-swift/Amplify/Categories/DataStore/DataStoreCategory.swift:21: Fatal error: DataStore category is not configured. Call Amplify.configure() before using any methods on the category.

ArtApp:

import SwiftUI
import UIKit
import Amplify
import AWSS3StoragePlugin

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        let storagePlugin = AWSS3StoragePlugin()
         do {
             try Amplify.add(plugin: storagePlugin)
             try Amplify.configure()
           print("Amplify configured with storage plugin")
          } catch {
            print("Failed to initialize Amplify with (error)")
          }
        return true
    }
}


@main
struct ArtApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

AmplifyDataStoreConfig:

import Amplify
import AWSS3StoragePlugin

final class AmplifyDataStoreConfig {
    static var shared = AmplifyDataStoreConfig()
    
    private init() {
       
    }
    
    func fetchArttist() async {
        do {
            let items = try await Amplify.DataStore.query(Artist.self)
            for item in items {
                print("artist id: (item.id)")
            }
        } catch let error as DataStoreError {
            print("Error querying items: (error)")
        } catch {
            print("Unexpected error: (error)")
        }
    }
}

LaunchView:

struct LaunchView: View {
    @State var isAnimating: Bool = false
    @State var isPresent: Bool = false
    var body: some View {
        HStack(spacing: 0) {
            ZStack(alignment: .trailing) {
                Rectangle()
                    .foregroundColor(.artOrangeLight)
                    .frame(width: 128, height: 128)
                    .offset(y: isAnimating ? .zero : -UIScreen.main.bounds.height)
                    .animation(.spring().delay(0.5), value: isAnimating)
                Text("art")
                    .foregroundColor(.artieLogoText)
                    .font(.custom(.gothamLight, size: 90))
                    .offset(y: isAnimating ? .zero : -UIScreen.main.bounds.height)
                    .animation(.spring().delay(1), value: isAnimating)
            }
            Text("ie")
                .foregroundColor(.artLogoText)
                .font(.custom(.gothamLight, size: 90))
                .offset(x: isAnimating ? .zero : UIScreen.main.bounds.width)
                .animation(.spring().delay(1.5), value: isAnimating)
        }
        .onAppear{
            isAnimating = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                isPresent = true
            }
            

            Task {
                await AmplifyDataStoreConfig.shared.fetchArttist()
            }
        }
        .fullScreenCover(isPresented: $isPresent) {
            OnboardingView()
        }
    }
}

Share
Improve this question


Load 7 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *