我正在尝试创建一个自定义 Cocoapod 来处理我的 iOS 应用程序的所有网络调用。我遇到的问题是,当我尝试在代码中引用一些本应属于我的新 Cocoapod/框架的文件时,却找不到它们。
我遵循了本教程 https://www.raywenderlich.com/5823-how-to-create-a-cocoapod-in-swift我成功创建了 Cocoapod .xcworkspace 项目(名为:ios-oauth2-rest-template)并将其添加到 bitbucket 中,并在 bitbucket 上创建了一个私有(private) PodSpec 存储库(名为:KPodSpec)(两个单独的存储库)。
我能够完成本教程,但我被困在“使用你的新 CocoaPod”部分。我能够运行以下命令将 Cocoapod 添加到我的 PodSpec 存储库中:
pod repo add KPodSpecs [Your RWPodSpecs Git URL]
pod repo push KPodSpecs ios-oauth2-rest-template.podspec
当我尝试在现有项目(名为:KApp)中使用我的新 pod 时,我的 Cocoapod 中的一些文件可以被引用,而其他文件即使在我 import ios_oauth2_rest_template
之后也不会自动完成。 。
我不确定我是否只是缺少 ios-oauth2-rest-template
的框架在我的里面KApp
项目。任何帮助将不胜感激。
KApp Podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '12.0'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://bitbucket.org/kpodspecs.git'
target 'KApp' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for KApp
target 'KAppTests' do
inherit! :search_paths
# Pods for testing
end
target 'KAppUITests' do
inherit! :search_paths
# Pods for testing
end
pod 'LBTAComponents'
pod 'SwiftyJSON', '~> 4.0'
pod 'TRON', '~>4.0'
pod 'ios-oauth2-rest-template', '~> 0.0.1'
end
ios-oauth2-rest-template podspec:
Pod::Spec.new do |s|
# 1
s.platform = :ios
s.ios.deployment_target = '12.0'
s.name = "ios-oauth2-rest-template"
s.summary = "My summary here"
s.requires_arc = true
# 2
s.version = "0.0.1"
# 3
s.license = { :type => "Proprietary", :file => "LICENSE" }
# 4 - Replace with your name and e-mail address
s.author = { "My Name" => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1974607c74787075597c74787075377a7674" rel="noreferrer noopener nofollow">[email protected]</a>" }
# 5 - Replace this URL with your own GitHub page's URL (from the address bar)
s.homepage = "https://bitbucket.org/myStuff"
# 6 - Replace this URL with your own Git URL from "Quick Setup"
s.source = { :git => "https://bitbucket.org/myStuff.git",
:tag => "#{s.version}" }
# 7
s.framework = "UIKit"
s.dependency 'Heimdallr', '~> 3.6.1'
# 8
s.source_files = "ios-oauth2-rest-template/**/*.{swift}"
# 9
#s.resources = "RWPickFlavor/**/*.{png,jpeg,jpg,storyboard,xib,xcassets}"
# 10
# s.swift_version = "4.0"
end
ios-oauth2-rest-template Podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '12.0'
target 'ios-oauth2-rest-template' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
use_frameworks!
# Pods for ios-oauth2-rest-template
pod 'Heimdallr', '~> 3.6.1'
target 'ios-oauth2-rest-templateTests' do
inherit! :search_paths
# Pods for testing
end
end
提前致谢。我在互联网上搜索过,但没有找到为什么会发生这种情况,而且我很困惑,因为我一开始就没有太多使用 CocoaPods 的经验。
更新 以下是一些截图
KApp 的 Pods 部分,用于显示我的一些类(class)。当我尝试使用ApplicationUtils
时它工作得很好并且自动完成,但是当我尝试使用 BaseClass
时它似乎找不到它。
设置下的构建阶段显示所有 30 个文件都在编译源下。这 30 个文件与 ios-oauth2-rest-template
中的 30 个文件匹配。 Xcode 项目。第31个文件是ios-oauth2-rest-template-dummy.m
。
最佳答案
感谢@balazs630,我能够解决这个问题。我必须确保我的访问控制设置为 public
或 open
才能访问它们。回顾我的代码,ApplicationUtils
是一个公共(public)类,而BaseClass
没有指定,所以默认情况下它是internal
,根据docs :
Internal access enables entities to be used within any source file from their defining module, but not in any source file outside of that module.
对于遇到类似问题的任何人,请检查以确保您的访问控制设置正确。以下是一些熟悉 Swift 中访问控制的资源:
关于ios - 自定义cocoapod找不到swift文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55977013/