Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Swift public Var to objective c class

I have following code in my Appdelegate class and want to access that in Objective C file for that I have already created Bridging file which works well for all methods.

public var loggedInUserModelObject = LoggedInUserModel(userDict:[String:Any]())

But when I try to access loggedInUserModelObject variable in objective C class it shows me This error.

enter image description here I used @objC before the class and before the variable too but no success. how can I access pubic variable in objective c file

like image 270
Gurpreet Avatar asked Jan 29 '23 06:01

Gurpreet


1 Answers

Are you using swift4?Rules of accessing variables have changed in swift 4.Instead of using @objc prefix in swift class use @objcMembers. This will expose all variables to objective c class. Example is given below.

@objcMembers class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate

If you want to expose single variable to swift class, use @objc before variable like the code shown below.

@objc public var loggedInUserModelObject : NSString?

like image 154
iosdev1111 Avatar answered Feb 04 '23 19:02

iosdev1111