0

I've seen a lot of questions and answers on this, but none of them seem to cover or solve my situation.

I have a project originally written in Objc, and now, one by one, I'm replacing all classes with Swift 4 syntax.

My problem is, that I cannot access swift properties in my Objective C files.

This is what I have so far:

I have this one swift file, called MessagesViewController.swift that starts as follows:

@objc class MessagesViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{

    @objc var mailboxNumber:NSNumber = 0
        ...

Then, in there is the objc class "MessagesBoxController" that needs to access mailboxNumber in the prepareForSegue method:

So, in MessagesBoxController.h I import the generated interface header:

#import "myProduct-Swift.h"

and in MessagesBoxController.m I have this boilerplate method:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    MessagesViewController *destViewController = segue.destinationViewController;
    NSIndexPath *selectedIndexPath = [_tv indexPathForSelectedRow];
    destViewController.mailboxNumber =selectedIndexPath.row+1;
}

So, the Swift class "MessagesViewController" is recognised fine; no complaints by the compiler whatsoever. Its properties though are not exposed:

auto complete doesn't suggest mailboxNumber and upon building the project, I get the error

"Property 'mailboxNumber' not found on object of type 'MessagesViewController *'"

What part is missing to make this work?

1 Answer 1

1

OK, So, the basic setup is correct. I ended up cleaning the project. I then got the message that "myProduct-Swift.h" could not be found. Then I quit XCode and deleted the derived data. That helped.

Sign up to request clarification or add additional context in comments.

1 Comment

I am still facing issue to access my Int & Bool from Swift to objective-C ... and getting this error : Property cannot be marked @objc because its type cannot be represented in Objective-C , Any suggetion ? .. I have used same header "MyProject-Swift.h.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.