LoginSignup
8
7

More than 5 years have passed since last update.

Realmを使ったプロジェクトでユニットテストを実行した時に出たエラー

Posted at

エラー内容

*** Terminating app due to uncaught exception 'RLMException', 
reason: 'RLMObject subclasses with the same name cannot be included twice in the same target. 
Please make sure '<Realmオブジェクトクラス名>' is only linked once to your current target.'

スクリーンショット 2016-01-25 9.19.50.png

状況

  • Realmを使ったプロジェクトのユニットテスト実行時に発生
  • Realmオブジェクトクラスがプロジェクトとテストの両方のターゲットに含まれていた
  • ユニットテストの中では特別Realmを使うようなコードは書いていなかった
  • 上記エラーは毎回必ず起きるわけではなく、数回に一回出るという具合

解決策

エラーメッセージ、下記stackoverflowに書かれている通りです。
Realmオブジェクトクラスは同じ名前で複数のターゲットで使おうとするとダメなようです。
なのでテストターゲットには入れないようにして、代わりにSwift2.0から導入された@testableを使ったらこのエラーは出なくなりました。

8
7
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
8
7