尝试使用私有Pod(Swift)中定义的协议时,XCode会显示“使用未声明的类型" [英] XCode says 'Use of undeclared type' when trying to use a protocol defined inside a private Pod (Swift)

查看:155
本文介绍了尝试使用私有Pod(Swift)中定义的协议时,XCode会显示“使用未声明的类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的团队陷入一种奇怪的境地,其中涉及一个基础项目+带有一些协议的私有pod.

I and my team are stuck in a strange situation involving a base project + private pods with some protocols inside.

我们的问题是我们无法从基本应用程序代码中访问某些(协议)标识符(在私有pod中定义).

Our problem is we can't access some of the (protocol) identifiers (defined in a private pod) from our base app code.

显然,我们的问题似乎与这两个堆栈溢出线程中描述的问题完全相同,但是它们的解决方案不适用于我们.

Apparently our problem seems to be exactly the same as the one described in these 2 stack overflow threads, but their solutions haven't worked with us.

线程1:在Swift中找不到源文件

线程2:已安装CocoaPod但看不到Swift代码

我们正在使用的骨架是这个:

The skeleton we're using is this one:

我们的Commons窗格(使用我们在基本应用中看不到的协议)是通过以下.podspec文件定义的:

Our Commons pod (with the protocol we can't see from our base app) is defined with this .podspec file:

Pod::Spec.new do |s|

  s.name         = "Commons"
  s.version      = "0.1.10"
  s.summary      = "Commons framework"

  s.description  = <<-DESC "Commons framework"
                   DESC

  s.homepage     = "http://EXAMPLE/Commons"

  s.license      = { :type => "Commercial" }

  s.author             = { "Author" => "author@mail.mail" }
  s.source       = { :git => "GITLAB_PRIVATE_URL/commons-iOS-Pod.git", :tag => s.version }

  s.source_files  = "Commons", "Commons/**/*.{h,m,swift}"
  s.exclude_files = "Commons/Exclude"

end

在基本应用程序中,我们具有以下Podfile(用于将Commons pod放置到主xcworkspace中).

From our base app, we have the following Podfile (to get our Commons pod onto our main xcworkspace).

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'

target 'ios-appbase' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  pod 'Alamofire'
  pod 'ViewDeck'
  pod 'JLRoutes'

  pod 'Commons', :git => 'GITLAB_PRIVATE_URL/commons-iOS-Pod.git', :tag => '0.1.4', :branch => 'develop'
  pod 'RestManager', :git => 'GITLAB_PRIVATE_URL/RestManager-iOS-Pod.git', :tag => '0.1.3'
  pod 'BaseClasses', :git => 'GITLAB_PRIVATE_URL/BaseClasses-iOS-Pod.git', :tag => '0.1.3'
  pod 'DesignManager', :git => 'GITLAB_PRIVATE_URL/DesignManager-iOS-Pod.git', :tag => '0.1.2'

end

我们已经将我们的协议定义为公共协议(如预期那样,因为它位于"Pods"项目中).

We've defined our protocol as public (as it's expected to be done, because it's living inside the 'Pods' project).

还有什么需要研究的?

PS:不仅我们的自定义协议在主应用程序中不可见",而且在Alamofire内部定义的协议也是如此,Alamofire是我们主应用程序中包含的另一个Pod.我们尝试使用它们,而XCode在编译时会抱怨.

PS: Not only our custom protocol is "invisible" from our main app, but also protocols defined inside Alamofire, which is another Pod included in our main app. We try to use them and XCode complains at compile time.

先谢谢了. 问候.

缩小问题范围,我们认为这是在编译时发生的事情.为什么?因为XCode能够通过按CMD + Click(在Pods文件结构中定义了两种协议)来解决错误的符号,但是编译器无法做到这一点,而它却抱怨使用未声明的类型"错误.

Narrowing our problems, we think it's something happening in compilation time. Why? Because XCode is able to solve the faulty symbols pressing CMD+Click (two protocols defined on our Pods file structure), but the compiler can't do it and it's the one complaining with the "Use of undeclared type" error.

推荐答案

希望,成功(!?)

我们正在定义的协议驻留在Framework Pod中,因此:我们在做什么错了?

The protocol we were defining was living inside a Framework Pod, so: What were we doing wrong?

显然,我们需要导入Framework的名称(而不是协议的类名称(!)).一种新手错误(?).

Apparently we needed to import the name of the Framework (not the class name of the protocol (!) ). Kind of a newbie error (?).

一旦我们在swift文件的顶部键入了"import Commons",所有"undefined xxxxxx"错误都将消失.

Once we typed "import Commons" on the top part of our swift file, all "undefined xxxxxx" errors disappeared.

不确定是因为导入的Pod是一个Framework项目,还是需要这个特定的导入部件,还是碰巧碰到了问题.

Not sure though if we needed this specific import part because the imported Pod was a Framework project, or we just hit the nail by chance.

给我的印象是其他一些类和从我们正在使用的其他Pod中导入的东西,不需要导入部分,您可以从一开始就直接使用它们.因此,我们的误解可能是由这个(?)引起的.

I have the impression some other Classes and stuff imported from some other Pods we're using, don't need an import part, and you can directly use them from the start. So our missunderstanding might have been caused by this (?).

无论如何,正如我之前说的,这些都是使用自定义Pod + swift +框架+某种程度上复杂的可扩展.app体系结构"的新手问题.

Anyway, and as I said before, these are newbie problems using "custom pods + swift + Frameworks + somehow complex escalable .app architectures".

我们希望这个问题及其解决方案可以为处于类似情况的未来开发人员提供一些启发.

Let's hope this problem and its (alleged solution) sheds some light onto future developers being in a similar situation.

问候.

这篇关于尝试使用私有Pod(Swift)中定义的协议时,XCode会显示“使用未声明的类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆