Reputation: 85
I'm currently working on SDK that incapsulates all networking with my back-end. I try to make a class according to the UML:
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!
Upvotes: 0
Views: 65
Reputation: 85
The problem was in: - public typealias APIResult<D:Decodable> = Result<D?, APIError> because it was declared as just typealias without public. Thanks for all!
Upvotes: 0
Reputation: 3352
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
Upvotes: 1