ios - 如何使用 Swift 制作 pod

标签 ios swift cocoapods

我尝试使用 Swift 创建 pod,但无法使其在 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 项目中,当我命令+单击标题 import TestSwift 时,我不能这样做

即使我声明它是公开的,我也看不到我的方法

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" => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8aebf8fefde5f8e1a4fee2caede7ebe3e6a4e9e5e7" rel="noreferrer noopener nofollow">[email protected]</a>" }
  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,请尝试将该文件添加到
构建阶段 -> 编译源

它应该看起来像这样:

enter image description here

假设您已正确完成一切 - 正确的 podspec 文件等 - 并且您的项目结构如下所示:

enter image description here

关于ios - 如何使用 Swift 制作 pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29861942/

相关文章:

ios - 嵌入 ViewController 时, View 未按预期使用 AutoLayout 进行布局

Kotlin MPP pod 集成失败

ios - 无法导入桥接头 xcode 6.4

iphone - 使用 asihttp 请求在表中发出带有进度条的多个请求

ios - 具有自定义宽度的 UISearchBar 在 UINavigationBar 向上滑动动画期间消失

ios - 替换 html 字符串中的特定单词

ios - Firebase 和线程 1

swift - Action 的多个参数/参数 - Swift

ios - 我可以将一个 iOS 应用拆分为两个或多个项目吗?

xcode - Cocapods - 无法将 pod ObjectMapper 更新到版本 3.3 错误 [!] 未知命令 : `ObjectMapper,`