Search code examples
iosswiftclasssdkencapsulation

SDK: iOS static library implementation


I'm currently working on SDK that incapsulates all networking with my back-end. I try to make a class according to the UML:enter image description here

but struggled with shared instance. I suppose it is a singleton instance and I made a single one like:

public class MIDNetwork {

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

but I can't understand why I am not able to call class's methods via shared instance. I import my static library in test project and try to call methods like this:

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

Here is my 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? { }
}

I tried to mark methods with public but after that I got an error:

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

Who could explain where did I make mistakes? Appreciate your answers, thanks!


Solution

  • The problem was in: - public typealias APIResult<D:Decodable> = Result<D?, APIError> because it was declared as just typealias without public. Thanks for all!