0

The project I work currently has Both Objective-C and Swift linked with the bridging header and everything works fine. but in one case where this particular viewController.h which is in Obj-c has swift imported already. when I try to access this viewController.h in another Swift controller it says '<#project-name#>-swift.h' file not found

Guide me how can I access this objC file in swift :(

Edited: detailed!!

I have a viewController.h file where I have implemented swift models by importing '<#project-name#>-swift.h'

but when I try to access this viewController.h from SecondViewController.swift, I have to add this #import "viewController.h" to the bridging header of my project. If I do so I am getting this error '<#project-name#>-swift.h' file not found

Raghav7890
  • 458
  • 3
  • 13
  • Possible duplicate of [How to import existing Objective C classes in Swift](https://stackoverflow.com/questions/24034409/how-to-import-existing-objective-c-classes-in-swift) – Zღk May 26 '17 at 12:28
  • Please check the link - https://stackoverflow.com/questions/26096402/xcode-myprojectname-bridging-header-h-does-not-exist – Ved Rauniyar May 26 '17 at 12:30
  • @Ved :: have updated my question...my issue is not on bridging header..but on reusing objc in swift which has bridging header.h imported!! Already – Raghav7890 May 26 '17 at 13:30

1 Answers1

1

If my understanding of what you are doing is correct, the problem is that the projectname-Swift.h header is included in a header (viewController.h) that is in turn imported in the bridging header.

The documentation at https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-ID122 talks about including the generated *-Swift.h header in .m files, not in headers, suggesting it should not be included in headers to avoid circular dependencies. You can still get away with including it in a header, but that will break if the header is included in the bridging header.

I would import *-Swift.h in viewController.m, not viewController.h. If you need to reference a Swift type as a property, argument, or return type in viewController.h, then you can use forward declarations, like

@class MySwiftModelClass;

If classes declared in viewController.h extend MySwiftModelClass, then things get a little trickier. Please post a more specific brief example if that is the case.

Anatoli P
  • 4,791
  • 1
  • 18
  • 22
  • Hey! thanks for the answer. pretty much You got what I was looking for... YES the documentation from apple says to import the bridging header to .m file to avoid circular dependencies.. Yes My class extends the swift in .h (my headers has some methods which returns a swift model) – Raghav7890 May 27 '17 at 02:22