Recently, I was looking to begin an iOS project that uses the DataStore service of AWS Amplify. To get familiar, I followed the 'Getting Started' documentation found at https://sandbox.amplifyapp.com/start#datastore and accepted all the defaults to create a simple Blog application.
When I was in the 'Test' stage and on the last part of step 4, my Xcode project was failing to find 'AmplifyModels' even though they were generated successfully and exist in the /amplify/generated/models folder.
This is the code
import SwiftUI
import Amplify
import AmplifyPlugins
@main
struct BlogApp: App {
public init() {
let dataStorePlugin = AWSDataStorePlugin(modelRegistration: AmplifyModels())
//let apiPlugin = AWSAPIPlugin(modelRegistration: AmplifyModels()) // UNCOMMENT this line once backend is deployed
do {
try Amplify.add(plugin: dataStorePlugin)
//try Amplify.add(plugin: apiPlugin) // UNCOMMENT this line once backend is deployed
try Amplify.configure()
print("Initialized Amplify");
} catch {
print("Could not initialize Amplify: \(error)")
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
This is the error
Cannot find 'AmplifyModels' in scope
Steps taken to try and resolve the error
I am running on Xcode 12.2. The reason that I decided to follow the 'Getting Started' documentation step by step is because I was failing with this same error for my own project I was creating, so I wanted to make sure that it was not some simple user error on my part.
Thank you in advance!
The instructions leave out one small step. You need to add the generated source files to the project so they'll get compiled.
pick menu "File > Add Files to ..."
select the amplify folder, and pick the 'Create groups' option