2

I have a Swift function public func doSomething( aKey : String, completed: @escaping (AModel?, TagError?)->()) {} that needs to be exposed to Objective C code for consumption. I have created an Objective C class wrapper like

@objc
public func doSomethingObjCWrapper(aKey : String) {
       anObject.doSomething(aKey: aKey) { (modelA, error) in
            if let whtModel = modelA {
                // All good

                DispatchQueue.main.async {
                    print("ok")
                }

            } else {
                print("\(error?.localizedDescription ?? "Unknown error")")
            }
        } 
}

to be called from Objective C code. Whenever the code gets triggered, I will always get EXC_BAD_ACCESS error in anObject.doSomething line. Any lead will be much appreciated.

aNa12
  • 145
  • 1
  • 10
  • 3
    Presumably the problem is with `anObject`. But you have told us nothing about what that is or where it comes from. We know nothing about the signature of `doSomethingObjCWrapper` or what Objective-C is handing you in the completion handler. Please be more informative if you want help. – matt Apr 16 '20 at 01:56
  • What is anObject? What anObjet's lifetime? Would you show code of anObject type definition? – Asperi Apr 16 '20 at 08:29
  • This link could be useful: https://stackoverflow.com/questions/24078043/call-swift-function-from-objective-c-class – Durga Vundavalli Apr 20 '20 at 17:57

1 Answers1

0

is anObject conform the NSObject protocol?

if not, you can try this way because of the root class of most Objective-C class hierarchies, from which subclasses inherit a basic interface to the runtime system and the ability to behave as Objective-C objects

Reference https://developer.apple.com/documentation/objectivec/nsobject

Kiel
  • 235
  • 2
  • 8