XCode says 'Use of undeclared type' when trying to use a protocol defined inside a private Pod (Swift)

自作多情 提交于 2019-12-11 06:40:02

问题


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

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.

Thread 1: Source files not found in Swift

Thread 2: CocoaPod installed but doesn't see Swift code

The skeleton we're using is this one:

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

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

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

What else should be looking into?

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.

Thanks in advance. Greetings.

EDIT1: 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.


回答1:


Whops, success (!?)

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

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

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

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.

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 (?).

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.

Greetings.



来源:https://stackoverflow.com/questions/39455301/xcode-says-use-of-undeclared-type-when-trying-to-use-a-protocol-defined-inside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!