SwiftでFontAwesomeKitを使う時にハマった事

fontawesomeのiconを使いたくて、FontAwesomeKitと言うライブラリを使う事にした。

FontAwesomeKit

マニュアルやその他サイトを参考に、以下の手順を行う。

  1. objective-c bridging headerを作成
  2. 作成したヘッダー内に以下を記述

    #import <FontAwesomeKit/FontAwesomeKit.h>

  3. 使用開始

    let gearIcon = FAKFontAwesome.gearIcon(withSize: 20)

「Use of unresolved identifier ‘FAKFontAwesome’」と言うエラーが発生

色々調べるが良く分からん…

how to integrated with swift? #46

というissueを見つけたけど、結局解決には至らず…。

cocoapodsのuse_frameworks!でインストールしたライブラリはbridging headerが不要?

FontAwesomeKitから離れて、swiftとbridging headerについて調べていくと、

How to Integrate Swift CocoaPods with a bridging header file

こんなのを見つけた。

When you use “use_frameworks!” in the Podfile as you are, you don’t need to import anything in the bridging header. Cocoapods is making frameworks for each of those pods for you, so you can just import them as if they were common frameworks directly on your swift file:

えー、マジでという事で、bridging headerを削除し、FontAwesomeKitを使いたいファイルで

import FontAwesomeKit

と記述したところ、上手くいった…。

CocoaPods 0.36 – Framework and Swift Support

何かこの辺に色々書いてあるそうだが、面倒くさくなって読むのは止めた。

こういうのを追求して疑問点を無くしていくのが出来るエンジニアなんだろうけど、趣味グラマにとっては動くようになれば良いのだ。

まとめ

脇道に逸れ過ぎず、動く物を目指す。

コメント

タイトルとURLをコピーしました