SDK: iOS 静态库实现

SDK: iOS static library implementation

我目前正在开发将所有网络与我的后端封装在一起的 SDK。我尝试根据 UML 制作一个 class:

但在共享实例方面遇到了困难。我想这是一个单例实例,我做了一个像:

public class MIDNetwork {

/// Class sigleton instance
static public let sharedManager:MIDNetwork = MIDNetwork()

但我不明白为什么我不能通过共享实例调用 class 的方法。我在测试项目中导入我的静态库并尝试调用这样的方法:

func handleRequest() {
    self.request = MIDNetwork.sharedManager.
    
}

这是我的 class:

    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 标记方法,但之后出现错误:

Method cannot be declared public because its parameter uses an internal type

谁能解释一下我哪里出错了?感谢您的回答,谢谢!

您必须声明您的 public 方法,如果出现错误

Method cannot be declared public because its parameter uses an internal type

表示你的一个参数不是public

例如函数:

func createRootIdentity(requestDataMode:MIDCreateRootIdentityRequest, handler: @escaping (APIResult<MIDIdentity>) -> Void) -> URLSessionTask? { }

MIDCreateRootIdentityRequestAPIResultMIDIdentity 是否已声明 public?

该函数取决于参数,因此要么声明所有内容 public,要么您不能使用它

问题出在:- public typealias APIResult = Result 因为它被声明为没有 public 的类型别名。谢谢大家!