Is it possible to add new swift viewController in objective C Project?


Hi,
My project is in Objective C.
Is it possible to add new swift viewController in objective C Project?

Accepted Reply

I imported "MyProjectName-Swift.h" in my ObjectiveC File.

Please clarify, in which file and where did you put #import "MyProjectName-Swift.h"?

Generally, you put #import "MyProjectName-Swift.h":
  • In .m file, not .h

  • After the line `#import "MyClassName.h"

Are you sure you followed these rules?

Replies

Is it possible to add new swift viewController in objective C Project?

YES.
If you find any difficulty to add a new Swift file to your project, please tell us the detail.
Hi,
Thanks for your reply.
Yes. i have difficulty in adding new swift file in my project.
Once i add a new swift view controller in my objective C Project, it asked me to add bridging file.
I added it.
And then , I imported "MyProjectName-Swift.h" in my ObjectiveC File.
When i build the project, it fails and shows errors
" '#pragma clang attribute pop' with no matching '#pragma clang attribute push' "
" Expected 'language' , 'definedin' or generatedDeclaration " in "MyProjectName-Swift.h"

Pls help to solve this issue

I imported "MyProjectName-Swift.h" in my ObjectiveC File.

Please clarify, in which file and where did you put #import "MyProjectName-Swift.h"?

Generally, you put #import "MyProjectName-Swift.h":
  • In .m file, not .h

  • After the line `#import "MyClassName.h"

Are you sure you followed these rules?
I put #import "MyProjectName-Swift.h" in .m file.

Added at line No 3 as shown below
line no 1 : #import "abcd.h"
line no 2 : @import ***;
line no 3 : #import "MyProjectName-Swift.h"

Now i replaced it in first line and the errors disappeared.
Working fine...It saved my day.
Thanks a lot OOPer