ios - 自定义cocoapod找不到swift文件

标签 ios swift xcode cocoapods

我正在尝试创建一个自定义 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 时它似乎找不到它。 The Pods section of the KApp, to show some of my classes.

设置下的构建阶段显示所有 30 个文件都在编译源下。这 30 个文件与 ios-oauth2-rest-template 中的 30 个文件匹配。 Xcode 项目。第31个文件是ios-oauth2-rest-template-dummy.mBuild phases under settings to show that all 30 files are under compile sources.

显示 ios-oauth2-rest-template 文件夹结构的图像 cocoa 足项目。 Image showing the folder structure of ios-oauth2-rest-template

最佳答案

感谢@balazs630,我能够解决这个问题。我必须确保我的访问控制设置为 publicopen 才能访问它们。回顾我的代码,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/

相关文章:

ios - 如何使用 Nib 执行到不同 View Controller 的 Segue?

android - 使用 LiveSDK 时出现 'redirect_url' 错误

swift - 'resignFirstResponder()' 返回 true 并且文本字段失去焦点但键盘不会关闭

ios - NSRange 永远不能为零,不允许比较 Swift

ios - 如何减小行间距?

ios - 当我在Xcode调试区域按下暂停按钮时,如何跳转到特定断点?

ios - swift promise 套件 : Equivalent to when() which executes sequentially?

c - 如何在 Mac OS 上安装包含可选字符串函数的 C11 编译器?

objective-c - 在phonegap上使用sharekit进行xcode中的重复错误(但对于phonegap-plugin则不如此)

ios - "Fixed leading and trailing constraints may cause clipping"错误?