Can't use Objective-C Pod Framework in Swift 2 project (“Use of undeclared type 'SMPageControl'”)

和自甴很熟 提交于 2019-12-23 05:07:33

问题


I have a Swift 2 project running on Xcode 7. I'm using CocoaPods (v 0.38.2 with use_frameworks!) and have already managed to get those frameworks working:

  • CryptoSwift
  • Pluralize_swift

Both Pods are written in Swift, so no problems so far. They work as charm.

Now I'm trying to use SMPageControl which is written in Objective-C. I've seen it's possible to use Obj-C Pods with Swift 2, tried a lot of different combinations but I can't get it to work. SMPageControl class doesn't show on autocomplete suggestions, and obviously when I try to use it the compiler throws Use of undeclared type 'SMPageControl'.

What I have done so far:

  1. Added pod 'SMPageControl' to my Podfile
  2. Ran pod install (I can see the Pod source/framework on Xcode project tree)
  3. Added SMPageControl.framework in Build Phases > Link Binary With Libraries (as I've done with the other frameworks that work)
  4. Created PROJECT_NAME-Bridging-Header.h and added it on the project's Build Settings (I can tell it's working because it threw errors until I got to import SMPageControl correctly)
  5. Added #import <SMPageControl/SMPageControl.h> to the file above

Up to here the project compiles without errors, but I can't get to use SMPageControl in my Swift classes. Tried import SMPageControl in the Swift file, but no luck (it doesn't even autocomplete). I understood it's possible, but I didn't find any example codes.

Is it really possible? If so, what am I missing?


回答1:


Finally got it to work, it turns out that I was actually missing something.

Along with all steps above, it's needed to import the framework at the top of the Swift file:

import SMPageControl

Since Xcode was not providing any autocomplete I thought it wouldn't be possible to do that. Once I added the import statement, the project compiled successfully and I was able to use SMPageControl() class.



来源:https://stackoverflow.com/questions/32996631/cant-use-objective-c-pod-framework-in-swift-2-project-use-of-undeclared-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!