sarunw
sarunw

Reputation: 8176

How to make pod with Swift

I try to create pod with Swift, but I can't make it work on Swift project.

I create very simple swift extension

import UIKit

public extension UIView {
    public func sw_foo() {
        println("bar")
    }
}

And Podfile

source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!

pod "TestSwift", :path => "../"

In Objective-C project I can import #import <TestSwift/TestSwift-Swift.h> and use method [self.view sw_foo];

But in Swift project I can't when I command+click into header import TestSwift

I can't see my method even I declare it public

import TestSwift
import UIKit


var TestSwiftVersionNumber: Double

It is very simple class, I don't know what I do wrong.

Tried on pod 0.36.3 and 0.36.4

Here is my project: https://www.dropbox.com/s/h6yyq8207iajlsv/TestSwift.zip?dl=0

and podspec

Pod::Spec.new do |s|
  s.name             = "TestSwift"
  s.version          = "0.1.0"
  s.summary          = "A short description of TestSwift."
  s.description      = <<-DESC
                       An optional longer description of TestSwift

                       * Markdown format.
                       * Don't worry about the indent, we strip it!
                       DESC
  s.homepage         = "https://github.com/<GITHUB_USERNAME>/TestSwift"
  # s.screenshots     = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
  s.license          = 'MIT'
  s.author           = { "Sarun Wongpatcharapakorn" => "[email protected]" }
  s.source           = { :git => "https://github.com/<GITHUB_USERNAME>/TestSwift.git", :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.platform     = :ios, '7.0'
  s.requires_arc = true

  s.source_files = 'Pod/Classes/**/*'
  s.resource_bundles = {
    'TestSwift' => ['Pod/Assets/*.png']
  }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  s.frameworks = 'UIKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end

Upvotes: 2

Views: 1012

Answers (3)

mcm
mcm

Reputation: 665

My issue had to do with extensions not being 'public'

So my files went from

extension UIView {
    //methods
}

to

public extension UIView {
    //methods
}

Upvotes: 1

sarunw
sarunw

Reputation: 8176

I finally found the problem, my sample project have the same name with my pod TestSwift. After change the project name everything working fine.

Upvotes: 0

Fengson
Fengson

Reputation: 4912

Seems like the file isn't visible to your project.
If this is .swift file, not a .framework, try adding the file to
Build Phases -> Compile Sources

It should look like this:

enter image description here

Provided you have have done everything right - correct podspec file, ect - and your project structure looks like this:

enter image description here

Upvotes: 1

Related Questions