Wednesday, 15 June 2011

Xcode 6 Swift + Objective-C Build Issues - Unknown Types due to Import Order? -



Xcode 6 Swift + Objective-C Build Issues - Unknown Types due to Import Order? -

i'm finding challenging construction mixed swift/obj-c ios application avoid build errors after converting classes swift.

this issue relating brief passage in swift documentation:

if utilize own objective-c types in swift code, create sure import objective-c headers types prior importing swift generated header objective-c .m file want access swift code from.

firstly, although documentation quite explicit importing -swift.h file .m files, there references types classes based in swift code in .h files of obj-c classes, end having import -swift.h in .h files of time. seems odd contradict doc, don't see how else these headers build, , has worked of time far.

the real problem occurs when generated -swift.h file contains compiler errors such as

unknown type name 'someobjcclass'

the way past these errors seems to sure said class reached prior -swift.h file, documentation suggests, unable figure out how order of build determined find myself importing kinds of obj-c headers on project prior generated header until working build. there's no way way go this, don't know right way.

how determine -swift.h header beingness included first time can required obj-c classes imported above it, , plenty -swift.h can imported in remaining places required, or collection of it's prerequisites need included above every time (which suppose not unlike i'm messily doing now)?

in experience far in order utilize objective-c classes in swift included .h files in -bridging-header.h , swift classes need used in objective-c code include -swift.h in .m files.

i haven't had issues unknown type. , references swift classes contained in .m files. if there swift class need reference in .h file, should forwards declaration @class myswiftclass.

objective-c xcode swift

No comments:

Post a Comment