Parameter func type could not be represented in Objc to Swift Bridging

Hi, does anyone know how could i represent the following type TypeA<TypeB> as a parameter of a func, if it's even possible, when declaring that func as @objc ?

  • Here is the signature of the func
@objc func someFunctions(
        someString: String?,
        success: @escaping (_ response: TypeA<TypeB>) -> Void,
        failure: @escaping (_ error: NSError, _ messageError: String) -> Void
    ) { .... }
  • And here the declaration insde the TypeA class which maybe it's the cause of the problem
class TypeA<T: Codable>: Codable {
    var list: [T]?

    var links: TypeC?

    var meta: TypeD?

    enum CodingKeys: String, CodingKey {
  • It gives me the following error referring to the 2° parameter which is TypeA<TypeB> of someFunctions

Method cannot be marked @objc because the type of the parameter 2 cannot be represented in Objective-C

the relevant parameter type must also be marked @objc.
you may try success: @escaping (_ response: Any) -> Void, with the corresponding typecasts.

1 Like

You mean i should mark @objc both TypeA and TypeB and every other type which is inside them? becuase i don't think i am able to add the @objc keyword to every type contained in TypeA and TypeB because not all type could be represented from Swift to Objc.

Regarding the Any solution, I think i have partially solve it meaning i will use Any as a result type and then when calling in Objc i will return only a single type like an array of type [TypeB] while when calling this API from swift i will use the original type TypeA<TypeB>.

To have a complete solution maybe i should implement generics on Objc side response or in some way cast the Any from Swift (id received in Objc) as TypeA<TypeB> but currently i am not able to do this.

you want the method to be marked @objc to be able calling it from objc with a parameter that objc can't express?

if you make it a simple minimal app (e.g. a git repo) would be easier to understand what you are after and then i or others can help.

you want the method to be marked @objc to be able calling it from objc with a parameter that objc can't express?

Yes that is my intention. From what i have read i should be able to use directly in Objc (or cast it from Any) the type TypeA<TypeB> as long as the types inside both type TypeA and TypeB could be represented in Objc. Am i right about this assumption or not?

Terms of Service

Privacy Policy

Cookie Policy