3

Please read the question.

I know that we can't call Swift generic methods from Objective-C as per this link

But in my case I have a project written in Objective-C and Swift. There is network library written in Swift having generic GET, POST, DELETE methods. For example below is GET method

public func get<T: ResponseDeserializer>(withDeserializer responseDeserializer: T, at relativePath: String? = nil, options: RestOptions = RestOptions(), callback: @escaping (APIResult<T.ResponseType>, HTTPURLResponse?) -> ()) {
    makeCall(relativePath, httpMethod: RestAPIManager.kGetType, payload: nil, responseDeserializer: responseDeserializer, options: options, callback: callback)
}

Where ResponseDeserializer is a protocol confirmed by few other classes.

Now my question is that is there any way to call above methods from Objective-C or should I implement a new network library for Objective-C.

I am looking for your valuable guidance.

Community
  • 1
  • 1
Gagan_iOS
  • 3,638
  • 3
  • 32
  • 51
  • it is not just about the _method_ only but all _parameters_ need to have an ObjC representation as well – which we don't know anything about, based on your current post. – holex Nov 14 '17 at 11:51
  • please let me know if I have to post complete code though it is too large. – Gagan_iOS Nov 14 '17 at 11:53

1 Answers1

1

No, even though it is a library, it is still written in Swift. And per the link you provided, you cannot call generic methods from Objective-C, since generics are a Swift feature.

tktsubota
  • 9,371
  • 3
  • 32
  • 40