heading_to_tahiti
heading_to_tahiti

Reputation: 795

Importing .swift file into Objective-C file results in Missing Context For Method Declaration Error

I am refactoring a few Objective-C ViewControllers and am trying to import a new Controller.swift file into a ViewController.m. However when I do that and run I get "Missing Context For Method Declaration" error for every method in the ViewController.m file.

this causes the error:

#import "ViewController.h"
#import "ContactsController.swift"

When I run without the .swift file import everything works fine. Also I have successfully imported this .swift file into other controllers in the above manner.

However when I change the order of the imports as such it works:

#import "ContactsController.swift"
#import "ViewController.h"

I have tried to research this, but to no avail. What are the possible reasons that the import could work in one order and not the other?

EDIT: Switching order does not work, it clears the errors on ViewController.m but throws errors on the swift file.

Upvotes: 0

Views: 248

Answers (1)

heading_to_tahiti
heading_to_tahiti

Reputation: 795

Ahhh.. It's been a loooong day. Just realized my mistake. I was trying to import the swift controller directly instead of the Project-Swift.h file, which is the proper way of accessing any swift files in objective-c;

to solve add in your ViewController.m file:

#import "<Project Name>-Swift.h"

Upvotes: 1

Related Questions