Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Cannot use library from Pod file

I'm using Typhoon library for Dependency Injection Framework. I use CocoaPod for installing this library. Here is my pod file:

target "typhoon-swift-demo" do
    pod 'Typhoon'
end

target "typhoon-swift-demoTests" do

end

I have installed successfully but when I open workspace project file. I type those line of code as Typhoon sample code:

public class ApplicationAssembly: TyphoonAssembly {

}

I meet error that my application doesn't recognize TyphoonAssembly I have tried to use some lines such as:

import Typhoon // not recogize typhoon
import TyphoonAssembly // not regconize

Please tell me how to fix this problem. What should I add before I can use library. Thanks :)

like image 294
hqt Avatar asked Oct 16 '14 19:10

hqt


2 Answers

You have to import the Pod header files using Objective-C and not Swift. So you'll be mixing the two languages if you want to use CocoaPods with Swift. Here's a great tutorial on how to accomplish this.

like image 183
quark Avatar answered Oct 05 '22 01:10

quark


In addition to Quark's answer, The Typhoon Swift example shows how to set up Typhoon for usage with Swift and CocoaPods.

Note that if you're using "application-style" tests, which is the default almost everywhere now, then the test target will already implicitly have the main target's dependencies. Therefore the test target should be declared exclusive. Example:

platform :ios, '7.0'

target :PocketForecast, :exclusive => true do

  pod 'Typhoon', :head

  pod 'CKUITools'
  pod 'ICLoader'
  pod 'NGAParallaxMotion'
  pod 'NSURL+QueryDictionary'
  pod 'OCLogTemplate'
  pod 'PaperFold', :git => 'https://github.com/jasperblues/PaperFold-for-iOS.git', :tag => '1.2-no-gesture-recognizers'

end

target :PocketForecastTests do
  pod 'Expecta', '~> 0.2.1'
  pod 'OCHamcrest'
  pod 'OCMockito'
end

inhibit_all_warnings!

If the test target is not declared exclusive, then it will have all of the application's libraries linked twice. This can cause problems in Typhoon's case, as it uses a lot of introspection.


Also note in the sample application, that there is a bridging header, that includes:

#import "Typhoon.h"


Typhoon Swift Example:

enter image description here

like image 37
Jasper Blues Avatar answered Oct 05 '22 00:10

Jasper Blues