SDWebImageで「unrecognized selector sent to instance」というエラー

広告:超オススメUnity Asset
  広告:超オススメUnity Asset

SDWebImageで画像付きテーブルビューの表示を超高速にしようとしていたときのMEMO。

SDWebImageのセットアップを済ませ、テスト用のシンプルなテストプロジェクトでは動作することを確認。

さて、本番用のアプリプロジェクト(だいぶいろいろ作りこんだもの)で「sd_setImageWithURL」を使おうとすると

[UIImageView sd_setImageWithURL:completed:]: unrecognized selector sent to instance 0x7fba9ac91e60

とかクラッシュしたりとかして使えず。。

Boost your iOS and macOS app performance with SDWebImage, the efficient library for asynchronous image downloading, caching, and much more.

の「Add Linker Flag」欄にあるように「”Build Settings”>”Linking” >”Other Linker Flags”」に「-ObjC」と入れろとのこと。=しかしビルド時に大量のエラー発生。

同ページに「-ObjC」の代わりに「-force_load SDWebImage.framework/Versions/Current/SDWebImage」を試せとあるので試す。=以下のエラーが発生

ld: file not found: SDWebImage.framework/Versions/Current/SDWebImage
clang: error: linker command failed with exit code 1 (use -v to see invocation)

「-ObjC」の代わりに「-force_load $(TARGET_BUILD_DIR)/libPods.a」を試せとの情報を見つける。=やはり同様にnot foundのエラー

「$(TARGET_BUILD_DIR)」の代わりに「$(BUILT_PRODUCTS_DIR)」を試せとの情報を見つける。=やはりnot found

ld: file not found: /Users/tshiraishi/Library/Developer/Xcode/DerivedData/・・・/Build/Products/Debug-iphonesimulator/libPods.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)

このディレクトリに何があるのかと思い、ファインダーで移動。

move

そこに「libPods-アプリ名-SDWebImage.a」というのを見つける。

最終的に

「”Build Settings”>”Linking” >”Other Linker Flags”」に
「-force_load $(BUILT_PRODUCTS_DIR)/libPods-アプリ名-SDWebImage.a」
と入れたらビルドできた!のでこれでよしとしておく。(←今ココ)

LinkerFlags