iOS Framework With Swift and Objective-C Where the Objective-C Uses Swift C -


i have framework building combines both objective-c , swift. issue of objective-c code within framework needs use of swift classes in framework. in order this, do:

#import "frameworkname-swift.h"  

in objective-c code in framework. , here first problem arises. -swift.h header not located xcode way. digging around in derived data, turns out -swift.h file located in framework/headers folder, in of seems odd. should -swift.h file exposed header framework? -swift.h file intermediary .h file, right?

to work around issue of not locating -swift.h, tried:

#import <frameworkname/frameworkname-swift.h> 

but, while locating -swift.h file, causes severe , compilation-fatal rash of cyclic dependencies in xcode, messages like:

cyclic dependency in module 'frameworkname' not build module 'uikit' 

here's in-situ:

enter image description here

thoughts?

i have incomplete answer this, more of partial explanation , workaround works me. here's think causing issue.

while apple let's call swift code in framework, objective-c in framework, if same objective-c class needs used swift run include/import cycle. here's situation have.

call objective-c class objc files objc.m , objc.h

now, since objc has use swift code needs import this:

#import <frameworkname/frameworkname-swift.h> 

which in case goes in objc.m file.

and since swift code needs use objc class, need following in framework umbrella .h file (the umbrella .h file named frameworkname.h):

#import <frameworkname/objc.h> 

now, if take @ frameworkname-swift.h file generated xcode (xcode 7.0.1 in case), find has import of #import <frameworkname/frameworkname.h>, forms cycle objc.m.

my workaround no more situation specific hack. turns out in case objc.m didn't critically need swift code. made code nicer , better engineered. so, comment , couple of lines of (objective-c) code in objc.m, worked around issue.

very insidiously, xcode 7 (at least) resistant getting out of issue once in it. is, when cyclic dependency error, can difficult have xcode stop telling you have it, if have taken cyclic dependency out of code. tried many things including removing of derived data files/folders, quitting xcode, , restarting mac, , found nothing worked consistently have xcode stop believing had cyclic dependency though i'd fixed issue.

this resulted in more difficult fix. had rebuild framework scratch, every step along way building , saving version control system i'd darn sure recover if xcode started being convinced had 1 of these cyclic dependencies. makes me have less faith in xcode. :(.

second fix: workaround (10/9/15)

i've found fix works in other cases:

1) clean/remove xcode derived data, including modulecache

2) build known working copy of xcode project (in case, had revision before started adding framework)

3) now, go xcode project framework included , attempt build. me, works.

this strictly work-around, , resolves cyclic dependency issue appears in different framework conditions me described in present question. i'm talking apple engineer right issue, see if can better fix. i'd rather not have apply workaround.

"final solution": namespace pollution (10/22/15)

i have figured out going on!! case of include file name space pollution. had objective-c class named "assert" (note upper case "a"), files assert.h , assert.m. have been using objective-c class (part of internal debugging) quite while. @ least year if not more, no apparent problem xcode. now, when started using in conjunction cocoa touch framework of own construction, problem came up. turns out if cleaned derived data first, /usr/include/assert.h file being picked up, , not own assert.h odd.

and, if derived data not cleaned , i'd built non-framework version of project first (for specific platform, e.g., iphone if building that), own assert.h picked up.

my fix pretty simple-- took 10 minutes. changed name of file/class smassert files smassert.h/.m. , changed references file in various places imported it. voila!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -