0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[AWS Amplify DataStore] [iOS] "Cannot find 'AmplifyModels' in scope" の原因が Target Membership の設定だった

Last updated at Posted at 2021-06-20

AWS Amplify DataStore の iOS アプリ向けチュートリアルをしていた際、
Initialize Amplify DataStore で次のコードを AppDelegates.swift に追加した時、
let dataStorePlugin = AWSDataStorePlugin(modelRegistration: AmplifyModels())の部分で
Cannot find 'AmplifyModels' in scope というエラーが表示されました。

swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    do {
        // AmplifyModels is generated in the previous step
        let dataStorePlugin = AWSDataStorePlugin(modelRegistration: AmplifyModels()) // ← ここでエラー ( Cannot find 'AmplifyModels' in scope )
        try Amplify.add(plugin: dataStorePlugin)
        try Amplify.configure()
        print("Amplify configured with DataStore plugin")
    } catch {
        print("Failed to initialize Amplify with \(error)")
        return false
    }

    return true
}

原因は、 AmplifyModels クラスが定義されている AmplifyModels.swift の Target Membership が [アプリ名]UITest のみだったためでした。

amplify codegen models コマンドでこのファイルをプロジェクトに追加した際、 [アプリ名]UITest のみが Target Membership に設定されていたようです。

バージョン

xcode: 12.5
amplify cli: 5.0.1

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?