0

Scenario: Objective-C ViewController creating a Swift view within its Swift extension.
In this case, I'm merely using a String vs UIView to make my question simpler.

Goal: to store the Swift View in the Objective-C View Controller for regional access.
That is, I want to make a local Swift variable visible thru-out the (ObjC/Swift) ViewController.
Here, I'm using the String 'myMessage' as an example.

//  MainViewController.h
#import <UIKit/UIKit.h>

@interface MainViewController : UIViewController
@property(nonatomic, strong) NSString *myMessage;
@end


// MainViewController.m
#import "MainViewController.h"

@interface MainViewController ()
- (void) doSomething;
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self doSomething];
    NSLog(@"Msg: %@", self.myMessage);
}

@end

Here's the swift extension:

import Foundation

extension MainViewController {
    func doSomething() {
        self.myMessage = "Mother had a feeling, I might be too appealing."
    }
}

I have the bridging header:

enter image description here Problem:

enter image description here

Question:
1) How do I expose the swift func()
... and to be able to access it?

Frederick C. Lee
  • 8,358
  • 15
  • 62
  • 97

0 Answers0