ios - SDK:iOS静态库实现
问题描述
我目前正在开发将所有网络与我的后端封装在一起的 SDK。我尝试根据 UML 创建一个类:
但在共享实例方面遇到了困难。我想这是一个单例实例,我做了一个像:
public class MIDNetwork {
/// Class sigleton instance
static public let sharedManager:MIDNetwork = MIDNetwork()
但我不明白为什么我不能通过共享实例调用类的方法。我在测试项目中导入我的静态库并尝试调用这样的方法:
func handleRequest() {
self.request = MIDNetwork.sharedManager.
}
这是我的课:
public class MIDNetwork {
/// Class sigleton instance
public static let sharedManager:MIDNetwork = MIDNetwork()
/// A network session
private var networkSession:URLSession = URLSession(configuration: .default)
///baseUrl is represented as an API endpoint
private static var baseUrl:URL = URL(string: "")!
// TODO: - Somehow figure out a client url
private var clientUrl:URL {
return self.clientUrl
}
func createRootIdentity(requestDataMode:MIDCreateRootIdentityRequest, handler: @escaping (APIResult<MIDIdentity>) -> Void) -> URLSessionTask? { }
func createDerivedIdentity(requestDataMode:MIDCreateDerivedIdentityRequest, handler: @escaping (APIResult<MIDDerivedIdentity>) -> Void) -> URLSessionTask? { }
func faceCheck(requestDataMode:MIDFaceCheckRequest, handler: @escaping (APIResult<MIDFaceCheckResult>) -> Void) -> URLSessionTask? { }
func getIdentityAdditionalInfo(derivedIdentityID:String, handler: @escaping (APIResult<MIDDerivedIdentityAdditionalInfo>) -> Void) -> URLSessionTask? { }
}
我尝试用 public 标记方法,但之后出现错误:
方法不能声明为 public,因为它的参数使用了内部类型
谁能解释我在哪里犯了错误?感谢您的回答,谢谢!
解决方案
You have to declare your public methods, if you get the error
Method cannot be declared public because its parameter uses an internal type
it means that one of your parameters is not public
For example for the function:
func createRootIdentity(requestDataMode:MIDCreateRootIdentityRequest, handler: @escaping (APIResult<MIDIdentity>) -> Void) -> URLSessionTask? { }
Are MIDCreateRootIdentityRequest
, APIResult
, MIDIdentity
declared publics?
The function is dependent on the parameters so either everything is declared public or you cannot use it
推荐阅读
- node.js - Passport JWT 策略提取选项
- dart - Flutter stateleswidget 返回一个列表
- python - 如何有效地改变数组中的某些值?
- swift - 如何确定 receivedTurnEventFor 是否是邀请?
- html - 如何调整按钮大小,使其对移动设备友好且仅显示符号?
- android - 将 com.android.tools.build:gradle 从 3.1.4 更新到 3.2.1 后,Android 应用程序构建失败
- linux - 我可以在调试器中跟踪控制流吗?
- java - 仅从地图中提取相关键
- java - 使用一个 log4j2.properties 的 2 个日志文件
- scala - 有没有办法使用 Scala 的 Range 类填充多维数组