创建 pod,为我的 pod 使用未声明的类型 类

Creating pod, use of undeclared type for my pod classes

我正在 swift 中创建一个 pod 以与 cocoapods 一起使用,但我在尝试使用它时遇到了一个奇怪的问题。 我的 pod 在 'pod install' 后正常下载,我可以通过 'import MyPod' 导入它。到目前为止一切顺利,但是当我尝试访问 pod 中的 类 时,我收到消息

 "Use of undeclared type 'NameOfTheClassIwantToUse'".

如果我转到 Pods 项目中的 pod 文件夹,所有文件都在那里,但我无法使用它。 我还注意到,当我使用 command+click 进入导入 'MyPod' 时,我只能看到很少的导入,而不是我所有的 类,例如:

import MyPodProjectName
import MyPodProjectName.Swift
import Foundation
import UIKit

public var MyPodProjectNameVersionNumber: Double

而其他进口产品具有进口时应该可用的所有 类。

有人知道我在这里遗漏了什么吗?

请务必将您 class 声明为 public,如此处所述

https://guides.cocoapods.org/making/using-pod-lib-create

如那里所述:

It's worth mentioning here, as this catches people quite often, a Swift library needs to have its classes declared as public for you to see them in your example library.

所以,只需在 class 上声明命名空间 "public" 就可以了

我遇到了同样的问题,这对我有用!

是的,您需要将您的 class、方法和相关变量声明为 public,并且不要忘记在您需要的 class 之上导入您的模块。