How to access private variable in swift child class from objective-c superclass?

1.3k Views Asked by At

I have project written in Swift, inside project I have pod written in objective-C. I inherited from objective-C framework and make swift file. This objective-C framework has many classes with many private properties which I need to access and edit them. Framework in pods so I can't edit it directly. Any way how I can do it? With KVC or Swizzle anything ?

1

There are 1 best solutions below

1
Gabriel On

First solution

Are you sure that you can not edit Pod script ? May be it's lock and the only thing you have to do is unlock the script and switch private variables to public (or delete the 'private' because in swift the variables are automatically public)

Second solution You can use protocol to access to this variables

I found for you a perfect tutorial Protocol/Delegate

Third solution

USE IT ONLY IF YOU HAVE NO IDEA: Use global variable, but it's not recommended to use this method. So if nobody here give you a better idea and you are stuck on this problem, use them until you find a better solution