ios - ModuleName-Swift.h file not found in xcode8 -
i'm trying work on mixed swift , objectivec project no luck.
my project made of 6 targets:
- app
- core
- coretest
- summary
- watchkit extension
- watchkit app
i've been able add swift class has 1 target membership (app) , uses objectivec code passing app-bridging-header.h "objectivec swift code" paradigm works charm.
instead, i'm struggling "swift objectivec code" paradigm. in specific case need use new swift class inside objectivec .m file member of 4 targets.
what i've been doing far this:
- add new swift file core project specifying 4 memberships (app, core, summary, watchkit ext)
- xcode asks create -bridging-header.h 3 projects core, summary , watchkit ext (app-bridging-header.h exists since used previously), , consent (don't know why creates files inside same group folder add swift class nevermind)
- i create swift class adding @objc key before class
- i go check if objective-c generated interface header name set modules, , yes is
- i go check if defines module set no in modules , set yes in main project, , yes is
- i write down imports -swift.h files 4 targets
- inside objective-c class try use new swift class, apparently seems work (even autocompletion)
- i try build project fails saying -swift.h file not found
i've followed mix , match guide of apple , many threads including this one seems apparently address same problem of mine doesn't work.
also have seen this , this didn't work.
have tried delete derived data cleaning whole project several times no luck.
edit 1 : more details
this declaration of swift class import realmswift
@objc class myclass: object {}
this snippet of usage of swift class inside objectivec
myclass *app = [[myclass alloc] init];
if avoid using #import ...-swift.h build fails saying i'm making use of undeclared idenfier "myclass" , sound.
if use #import ...-swift.h files says module x cannot find module y , on.
edit 2 : swift module name
by looking @ swift_objc_interface_header_name property of each target i've seen built using syntax $(swift_module_name)-swift.h need change swift_module_name module_name?
edit 3 : imports
this set of imports swift headers in .m objectivec file. i'm using module names specified in relative build settings properties. notice 1 has '_' character since watchkit extension target has space in target name.
#import "projectname_app-swift.h" #import "projectname_core-swift.h" #import "projectname_summary-swift.h" #import "projectname_watchkit_extension-swift.h"
edit 4 : cross visibility of -swift.h files
i've tryed following:
- added swift class in target app
- xcode created bridging header
- inserted #import "projectname_app-swift.h" in objectivec file used app
- made use of swift class inside file
- it compiles! , i'm able use swift class
when swift class defined multiple targets , objectivec file used multiple targets doesn't work. build errors this: target x -> "projectname_targety-swift.h" file not found. seems target cannot see other targets -swift.h files.
what doing wrong? help
the assumption made in edit 4 turned out correct one. if project has multiple targets "-swift.h" files cannot imported in 1 .m objectivec file.
so there 1 solution must adopted , change swift_objc_interface_header_name build setting , making same across different targets. change instruction generates property $(swift_module_name)-swift.h $(project_name)-swift.h explained here
it possible set product module name setting in build settings same across modules (i set $(project_name)), -swift.h file generated has same name across modules. eliminates need adding/checking preprocessor macros.
after doing clean build folder pressing alt , going product menu. since name of header shared among targets can imported once in .m objectivec file , targets can benefit swift classes.
if after building still shows error, ensure header can reached xcode cmd clicking on name. should open file contains code similar this:
swift_class("_ttc27projectname_summary11myclass") @interface myclass : nsobject - (nonnull instancetype)init objc_designated_initializer; @end
if need ensure headers being generated open terminal , use command
find ~/library/developer/xcode/deriveddata -name "*swift.h"
you should see 1 header each target
another issue happened me after changes started giving errors on objectivec code didn't touch. problem due position of import, reported here:
exactly @ top of .m file #import hidden bridging header can make difference. usual sign of trouble “unknown type name” compile error, unknown type class declared in objective-c. solution #import .h file containing declaration unknown type in objective-c files well, before #import hidden bridging header. having can annoyance, if objective-c file in question has no need know class, resolves issue , allows compilation proceed.
at end code compiles , runs on device , simulator!
Comments
Post a Comment