2
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 5 years have passed since last update.

自作クラスをテストしようとしたら、Ambiguous use of '***' とかいうエラーがでた(´・ω・`)

Last updated at Posted at 2016-04-07

クラスっていうか extensionだけども
(ObjC は未確認)

経緯

Swift における join の関数ちょっとなげえよな
ってことでこういう Extension なファイルを作ったわけです

だけど・・・

ArrayExtension.swift
extension SequenceType where Generator.Element == String {
    // 通る
    public var join: String {
        return self.join("")
    }
    // 通らない
    public func join(separator: String) -> String {
        return self.joinWithSeparator(separator)
    }
}

Ambiguous use of 'join'

テストクラスで、プロパティの join は通るのに、
ファンクションの join が表題のエラーを起こすわけです
でもテストじゃなければビルドが通る
Why? (´・ω・`)

原因

Xcode の右側に Target Membership という項目があって
普通はこんなんになってるはずなんですが↓

  • [ProjectName]
  • [ProjectName]Tests
  • [ProjectName]UITests

今回はテストするからこういうかんじなんかなー(ぽえー)
って Tests の方にもチェックを入れてたので
エラーが起きてしまいました

  • [ProjectName]
  • [ProjectName]Tests
  • [ProjectName]UITests

んー 時間かえせ! (´・ω・`)

ついで

↑の ArrayExtension.swift のテストファイルの
ArrayExtensionTests.swift の方も、ターゲットを2箇所チェックしてましたが
こっちはこういうエラーがでます

Cannot load underlying module for 'XCTest'

こっちはすぐ気づきましたが、Ambiguous use of...
は他の原因でも発生するっぽくてむだにいろいろ探して気づかなかった

2
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
2
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?