31

I have created a framework which I want to use in my OS X app. Since updating to Xcode 7 on El Capitan, when I try to command-click on the import statement, Xcode goes to the following view.

enter image description here

How can I get Xcode to display the Swift representation properly? I've had it happen before, and my solution was to recreate every project file which I don't want to do again.

David Skrundz
  • 13,067
  • 6
  • 42
  • 66

9 Answers9

38

From my experience there are two possible causes for this issue. The first one is that your framework can't be located. To fix this you need to go to target's Build Settings and add a path to Framework Search Paths either an absolute:

/Users/{user}/path-to-framework-parent-directory

or relative to project directory:

$(PROJECT_DIR)/path-to-framework-parent-directory

Another possible cause is that the path to your framework contains a space in it. I found that it doesn't matter whether you try to escape it with backslash ../Project\ Name/frameworks or take the whole path in double-quotes "../Project Name/frameworks". The result would be that SourceKit could not load the module.

Note that $(PROJECT_DIR) could expand to a path with a space in it and it would too result in the same error. So it looks like a bug in Xcode/SourceKit (I tried the latest Xcode 7.2-beta3 and the bug is still there).

My repository was on the second hard drive /Voluems/Macintosh HD/Repos. I just renamed the hard drive to HD, so the path looks like /Volumes/HD/Repos and the problem was gone.

Max S.
  • 516
  • 4
  • 5
  • Thank you. I was using PLATFORM_DISPLAY_NAME to put the libraries in my Lib folder. The value for max is "OS X" which was causing the problem. Creating my own constant without the space solves the issue. – David Skrundz Nov 19 '15 at 19:58
  • 7
    Trick with removing space from the path helped me. I had this problem with frameworks build by Carthage. Thanks! – Tomasz Bąk Nov 24 '15 at 13:28
  • @TomaszBąk Facing still same issue Please help me to resolve. – Zalak Patel Dec 10 '15 at 12:11
  • 1
    Check for spaces in your project path. If you have something like this `/Users/jalak patel/Documents/xcode workspace/project/` replace it to `/Users/jalak_patel/Documents/xcode_workspace/project/` or some other path without whitespace. This is what helped me to resolve this. – Tomasz Bąk Dec 10 '15 at 12:16
  • 1
    Spaces in the path was what cause this error for me. – loomer Sep 13 '16 at 12:00
  • Genius... had a space in a parent directory for the whole project. Thanks! – Hunter Lee Brown Feb 13 '17 at 02:19
1

Running Product->Clean, Product->Build is what worked for me.

myQwil
  • 442
  • 3
  • 11
1

Max S. answer pointed me in the right direction, however I was using the 'recursive' option for my framework path.

To get things to work I had to explicitly add a path to directly the framework in question's immediate parent directoy (as oposed to just having a path to one of its higher up directories with the 'recursive' option set).

HTH

Oliver Pearmain
  • 19,885
  • 13
  • 86
  • 90
1

I had this problem too and the other solutions didn't work. I finally figured it out in my case:

The target name cannot have a space in it either

To rename it:

  • Go to your project settings
  • Expand the target list column on the left if not already there
  • Click on the relevant target once (or press Enter or Tab when having it selected) and type in the new name without the space
Silvan Mosberger
  • 1,786
  • 14
  • 19
1

Weirdly, just changing the name of my folder from 'Developer' to 'Development' fixed the issue from me.

DardanM
  • 95
  • 8
0

In my case, I have created a framework for my SDK along with podspec for making it cocoa pod.

I had the same problem when i use my SDK and it fixed when I imported Foundation API to the file where I am consuming my SDK

import Foundation

Rakesh Yembaram
  • 433
  • 4
  • 7
0

Here is another potential solution - one that worked for me:

After importing the framework I never built for simulator, only for real devices. Swift Modules were not showing up, same error. Then I built for Simulator and it suddenly worked, I could see the Swift Modules.

The reason is that when I make my framework, I have a step that copies the swift modules from the iphonesimulator build to the universal build, but does nothing with the modules from the iphoneos build. So my guess is that this is why it didn't work.

Note: once I selected simulator and built it started working all the time, regardless of the build destination.

Tumata
  • 1,507
  • 1
  • 11
  • 14
0

In my case the issue was because the framework could not be located. Thanks to @Max S. suggestion, I have added the framework parent directory to the Framework Search Paths and then cleaned the build folder Product > Clean Build Folder. But the issue was still there. I tried to remove Xcode Derived Data folder completely but still nothing. So after some other failed attempts, I restarted Xcode and the magic happened, the issue was gone.

So in case the steps pointed out by @Max S. are not enough, try also to restart Xcode

Too Happy
  • 1
  • 1
  • Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? **If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient.** Can you kindly [edit] your answer to offer an explanation? – Jeremy Caney Aug 07 '23 at 03:05
0

Give it a shot by changing the target device. Instead of picking a physical device, opt for a Simulator instead. Then, try using the command-click action to open a documentation in Xcode.

Mayur Rathod
  • 361
  • 3
  • 13