PureLayout in Swift with Cocoapods

2.6k views Asked by At

Using cocoapods-0.37.2 Here's my Podfile:

platform :ios, "8.0"
use_frameworks!

pod "GoogleMaps"
pod 'FontAwesomeKit'
pod 'PureLayout'

I'm trying to import PureLayout in my .swift file like this:

import PureLayout

class ViewController: UIViewController {
...

But I get error:

No such module 'PureLayout'

Why??? I thought that Cocoapods creates -Bridging-Header.h by itself when using use_frameworks! ?

3

There are 3 answers

0
Daniel On

I did not use the use_framework option but I used PureLayout in Swift with CocoaPods without issues.

  • My Podfile only has one line pod 'PureLayout'.
  • I created the <Your Module>-Bridging-Header.h file myself as instructed by Apple here. I added a line #import "PureLayout.h". I've also updated my target build settings to enter the bridging header file name as per instructions.
  • In the .swift file where I want to use PureLayout, I did not need to have import PureLayout. It would give me an error as you mentioned. The auto layout calls would just work, since it's defined through bridging header.

One side point - the test target would fail to compile if you add bridging header file to its build settings. So make sure the bridging header update is done on target not project level.

I guess the current README in PureLayout github page is a bit outdated, since it currently asks you to do import PureLayout in the .swift file. I added a comment in this README enhancement issue too.

0
Max Phillips On
  1. install the podfile
  2. open your .xcworkspace
  3. put your import PureLayout statement in, get the error
  4. delete the statement
  5. clean your product
  6. build your product
  7. put your import PureLayout statement back in

This has been common occurence and fix for me when using outside frameworks.

1
ishiahirake On

spacemonkey's method work for me. In that case, you don't even need a -Bridging-Header.h file.

As for FontAwesomeKit, since it contains some resource file(xx.ttf, xx.otf, etc), you should add this file to project to make it work. Like following shows:enter image description here

Clean your project and recompile, then you are done.

Following is my demo for this:

import FontAwesomeKit
import ChameleonFramework
import SnapKit

class ViewController: UIViewController {

    @IBOutlet weak var imageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let iconSize : CGFloat = 128;
        let codeIcon = FAKFontAwesome.codepenIconWithSize(iconSize);

        imageView.image = codeIcon.imageWithSize(CGSizeMake(iconSize, iconSize));

        view.backgroundColor = UIColor.flatGreenColorDark();
    }
}

PS. Since you use swift, maybe the SnapKit Layout framework will much suitable than PureLayout.