2
2

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.

複数のライブラリを入れた場合にResultが干渉してエラーが出てしまうケース

Last updated at Posted at 2020-12-04

複数のライブラリを使用していると
別々のライブラリで同じ命名が使われている場合にエラーが出ます。

今回はもともとNukeを使っていて、そこにURLEmbeddedViewを
追加導入したところ、下記コードにて

Nuke.loadImage(
    with: imageURL,
    options: ImageLoadingOptions(),
    into: cell.fullImageView, progress: nil) {
        (result: Result<ImageResponse, ImagePipeline.Error>) in

このようなエラーが発生しました。

Generic type 'Result' specialized with too many type parameters (got 2, but expected 1)

Xcodeでエラーを詳しく見てみましょう。
左パネルの①のあたりをクリックすると原因箇所に飛ぶことが出来ます。

CleanShot 2020-12-04 at 11.png

②のあたりを見てみるとURLEmbeddedViewは独自にResultというenumを定義していますね。
ところでSwiftは5系になってからResultという機能を実装しました。

NukeはSwiftのResultを使っています。
SwiftのResultとURLEmbeddedViewのResultが干渉してしまっているのですね。

Xcodeから見るとResultと書かれても
Swift.ResultかURLEmbeddedView.Resultかわかんないわけです。

なので普段は省略しているSwift.Resultという風にどの名前空間なのかを
明示してあげることでXcodeが迷わなくなるって感じです。

というわけで、こんな風にすると修正できました。

Nuke.loadImage(
    with: imageURL,
    options: ImageLoadingOptions(),
    into: cell.fullImageView, progress: nil) {
        (result: Swift.Result<ImageResponse, ImagePipeline.Error>) in

参考資料:

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?