我尝试使用 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
,请尝试将该文件添加到
构建阶段 -> 编译源
它应该看起来像这样:
假设您已正确完成一切 - 正确的 podspec 文件等 - 并且您的项目结构如下所示:
关于ios - 如何使用 Swift 制作 pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29861942/