I'm trying to pass data from an objective-c ViewController to a Swift ViewController and I'm getting this error in my Objective-C controller:
Property 'type' not found on object of type 'UIViewController'
My Objective-C code:
UIViewController *mainController = [self.storyboard instantiateViewControllerWithIdentifier:@"IdentitySelfieViewController"];
mainController.type = "passport";
[self.navigationController pushViewController:mainController animated:YES];
Import into the Bridging-header file:
#import "PassportViewController.h"
And created the corresponding String into my Swift View Controller
let type = ""
Thank you for any help
The Solution to your problem is like that :
First in your Swift Controller add the @Objc
before the class keyword like that :
@objc class ViewController: UIViewController
and that in that controller create a variable like that :
public var myValue:String = ""
After this in your Objective-C
ViewController you need to import this and keep in mind this is very important.
#import "TargetName-Swift.h"
TargetName should be replaced by your target name. After this you can easily call the variables of that Swift Controller like that:
ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC"];
vc.myValue = @"Hello";
This is your swift class
Step 1:
class SwiftClassController: UIViewController {
//Required variables
@objc var deviceId: String?
@objc var deviceObj: CustomType?
Step 2:
In Objective C class import #import "YourProjectName-Swift.h"
Step 3:
In your Objective C class access variable from Swift file
YourViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"YourVC"];
vc.deviceId = @"1234567";
vc. deviceObj = yourCustomObject;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With