问题
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:
- Added
pod 'SMPageControl'
to myPodfile
- Ran
pod install
(I can see the Pod source/framework on Xcode project tree) - Added
SMPageControl.framework
in Build Phases > Link Binary With Libraries (as I've done with the other frameworks that work) - 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 importSMPageControl
correctly) - 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