Swift: Cannot use library from Pod file
Asked Answered
S

4

9

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 :)

Skeen answered 16/10, 2014 at 19:12 Comment(0)
B
14

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.

Bixby answered 16/10, 2014 at 20:6 Comment(2)
Nice :D thanks so much :D it costs me amount of time :D just because I want to jump directly into swift before learning anything basic :DSkeen
That one didn't work for me. This one was better blog.ios-developers.io/parse-backend-with-swiftCloven
A
3

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

Alcohol answered 17/10, 2014 at 1:23 Comment(2)
thanks :) I have read project's pod file, but I don't understand why author writes that. Now I can understand clearly :D Your library + demo are great, not only for this framework library but also for whom try to learn ios programming :)Skeen
:) Would you be so kind as to add a comment to the Podfile explaining the above, and send a pull request? Seems like we should have included that explanation.Alcohol
L
2

I think this needs an update. I have started recently developping Swift applications and, coming from a Java background, searched for a framework like Spring. The best I found is Typhoon. I didn't find a good introduction for newbies however, so I made a scratch project to try it out.

I integrated Typhoon by:

  1. Installing cocoapods
  2. Creating a basic podfile with a "use_frameworks!" line like here
  3. pod install
  4. Adding the "TyphoonInitialAssemblies" array to my plist file
  5. Create a first assembly and add it to the array in the plist

In the assembly,

import Typhoon

public class MyAssembly:TyphoonAssembly{}

Works like a charm!

Luetic answered 20/4, 2015 at 7:55 Comment(0)
S
1

You have even met this error.

I fixed by way: => remove "platform :ios, 'x.0'"

use_frameworks! target 'LateManagement' do pod 'Alamofire' pod 'SwiftyJSON' end

Salmonella answered 25/8, 2016 at 4:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.