如何使用 Swift 制作 pod

How to make pod with Swift

我尝试使用 Swift 创建 pod,但无法在 Swift 项目上运行。

我创建了非常简单的 swift 扩展程序

import UIKit

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

和 Podfile

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

use_frameworks!

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

在 Objective-C 项目中,我可以导入 #import <TestSwift/TestSwift-Swift.h> 并使用方法 [self.view sw_foo];

但是在 Swift 项目中,当我命令+单击进入 header import TestSwift

时我不能

即使我声明了我的方法也看不到它public

import TestSwift
import UIKit


var TestSwiftVersionNumber: Double

很简单class,不知道自己做错了什么

在 pod 0.36.3 和 0.36.4 上试过

这是我的项目:https://www.dropbox.com/s/h6yyq8207iajlsv/TestSwift.zip?dl=0

和 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" => "artwork.th@gmail.com" }
  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

您的项目似乎看不到该文件。
如果这是 .swift 文件,而不是 .framework,请尝试将文件添加到
构建阶段 -> 编译源代码

它应该是这样的:

前提是您已完成 所有 正确 - 正确的 podspec 文件等 - 并且您的项目结构如下所示:

我终于找到了问题所在,我的示例项目与我的 pod TestSwift 同名。更改项目名称后一切正常。

我的问题是扩展名不是 'public'

所以我的文件来自

extension UIView {
    //methods
}

public extension UIView {
    //methods
}