2

In my project i have many swift classes that extend generic classes. And Now i'm in a need to send data from objective-c class to these swift classes. Is there any possible way to do this ?

I have tried using @objc before class as shown below image 1 but it didn't allow me to do this.

I followed this answer stack link. But i checked when i run my app with this code it dint create the variable in the Project-swift class as shown in below image image 2 as the variable is not created here so it gives error while calling the variable in objective-c class.

Kindly help out with better solution.

1 Answer 1

0

I got my solution by creating another class which contain a protocol and i indirectly call the generic extended class.

class EntityDataTable :BaseData<EntitySw> {
}

this is the generic extended class

and the another class i made to indirectly access this class in objective-c is

@objc class EntityService : NSObject {
 var entityProtocol:EntityDataProtocol?

 override init() {
    super.init()
    entityProtocol = returnDataObject()
 }

  func returnDataObject() -> EntityDataTable {
    return EntityDataTable()
  }
 }

@objc protocol EntityDataProtocol{
  func addFromService(source: CWEntity)
  func getAll() -> [EntitySw]
}

Then i imported the Project-swift.h file in objective c class and made the object of swift class

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.