简体   繁体   中英

Passing data from view controller in Objective C to controller in Swift

I'm trying to pass a value from a "pictureView" view controller written in objective C to a "profileView" view controller written with swift. I am trying to use the prepare for segue method using the following code

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"unwindToProfileView"]){
    profileView *controller = (profileView *)segue.destinationViewController;
    controller.valueToPass = "PassedValue";
   }
}

The problem i'm running into is the "profileView" view controller is not recognized when called from the above method in objective C and xcode is throwing an error. I'm not sure if this is the correct way about transferring data from objective C to swift view controller or if I need to do something in the header or profileView.swift file.

Hopefully this is not a duplicate. I haven't been able to find anything regarding transferring data from objc VC to swift VC. Any help would be great.

Add an Objective-C Bridging Header and import the "profileView" view controller in that bridging header. You will then be able to reference the "profileView" view controller.

This isn't really an answer to my question, I never really got it working the way I wanted. But the way I got around the problem was creating a global variable in Obj C that Swift was able to see. You just have to make sure that global variable is included in your bridging header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM