105

So here's my procedure. I create a new Podfile in the project directory, then I added the following

platform :ios, '9.0'
use_frameworks!

target 'CPod' do
pod 'AFNetworking', '~> 2.5'
pod 'ORStackView', '~> 2.0'
pod 'SwiftyJSON', '~> 2.1'
end 

I fire off pod install, and everything goes well, open up the xcworkspace. I then go over to ViewController.swift and if I try to import a pod I get No such module 'SwiftyJSON', if I were to do import SwiftyJSON. Any ideas?

EDIT: SwiftyJSON is a Swift based module, not Obj-C

Idris
  • 1,658
  • 4
  • 16
  • 21
  • 1
    possible duplicate of [Swift: Cannot use library from Pod file](http://stackoverflow.com/questions/26412122/swift-cannot-use-library-from-pod-file) – Rugmangathan Jun 26 '15 at 05:21
  • That would be the case for `AFNetworking `, but that's a different story. `SwiftyJSON ` is a Swift library, therefore that post doesn't answer the question. @Rugmangathan – Idris Jun 26 '15 at 05:34
  • which version of cocoapods are you using? – Michael Dautermann Jun 26 '15 at 05:43
  • I believe it it `0.37.2` @MichaelDautermann – Idris Jun 26 '15 at 05:53
  • @Idris had the exact same issue. May be an Xcode 6.3.2+ problem. – rb612 Jun 26 '15 at 07:17
  • I'm running on Xcode 7, so that might be an issue, doubt it though. @rb612 – Idris Jun 26 '15 at 19:17
  • Any luck? Im running xcode 6.4 just installed cocoapods and tried using it. None of my pods can be imported. `platform :ios, '8.0' use_frameworks! target 'QContact' do pod 'SwiftyJSON', '~> 2.2' pod 'SwiftAddressBook', '~> 0.4' pod 'MaterialKit', '~> 0.3' pod 'DynamicBlurView', '~> 1.0' end target 'QContactTests' do pod 'SwiftyJSON', '~> 2.2' pod 'SwiftAddressBook', '~> 0.4' pod 'MaterialKit', '~> 0.3' pod 'DynamicBlurView', '~> 1.0' end` – user1086377 Sep 17 '15 at 00:14
  • Upgrade to Xcode 7, its out now @user1086377 – Idris Sep 20 '15 at 17:37
  • You don't need to use "import SwiftyJSON" right? It's already included in the project when added in the header file. I never got both obj-c and swift pods working in my projects though. Impossible as far as I know. It's either only obj-c pods or swift pods. – Orion Mar 21 '16 at 15:50
  • This solved it for me: http://stackoverflow.com/a/34196203/1101509 – Andrea Lazzarotto Dec 09 '16 at 15:04

28 Answers28

130

Try adding the Pods framework to your build scheme and building the framework. After you've built it, build/run your project.

Steps:

  1. Scheme menu > Manage Schemes > check Pods > Close manage

    enter image description here

  2. Select Pods from the scheme menu.
  3. Build Pods.
  4. Select your project from the same menu, then build/run it.
saurabh
  • 6,687
  • 7
  • 42
  • 63
Micah Benn
  • 1,321
  • 1
  • 10
  • 8
40

You must reopen project .xcworkspace file(not .xcodeproj) after install your podfile.

  1. Clone the repo with CocoaPods
  2. Open YourWorkspace/YourApplication.xcworkspace
  3. Select the app u want to run Add SwiftyJSON.framework in embedded binaries for that project Hit Run

Happy Coding :)

Asil ARSLAN
  • 1,066
  • 2
  • 14
  • 31
  • 1
    THANK YOU!! this was exactly what I needed. I had no idea about workspaces and had always been opening the xcodeproj file. – Ira Herman May 02 '19 at 21:45
  • 1
    Worked great for me! Thank you! – Lynn_Yang May 03 '21 at 12:05
  • Real trick here is don't open "project .xcworkspace" from the command line and make sure that xcode and any emulator are closed. When you open xcode, you should see "your project" with a blue icon and "Pods" as another project also in blue. – user1094125 May 23 '21 at 22:17
  • @user1094125 I guess they get confused because their names are similar. It happened to me tried first time. :) – Asil ARSLAN May 24 '21 at 17:22
  • 1
    Some solutions are so simple that sometimes I really think they aren't work. In my case, your solution helped me to figure out that I wasn't opening the .xcworkspace file because I double clicked at my Framework directory. It's a kinda weird behavior from Xcode, but it happens. – Marcos Rocha Jan 19 '22 at 19:07
  • @MarcosRocha I'm really glad to hear that. Can you up to my solution. Maybe we can help more. :) – Asil ARSLAN Jan 19 '22 at 19:27
35

You may also try re-installing pods using:

pod deintegrate

and then

pod install

This fixed this issue for me

Vishal
  • 2,030
  • 22
  • 27
  • sometimes it's necessary to run these commands twice... Additionally I've run rm -rf ~/Library/Developer/Xcode/DerivedData/* command – mkul Jun 23 '18 at 10:57
  • I did this and then build the pod scheme and the library scheme then it work. – Bhimbim Aug 14 '19 at 08:50
  • Such a simple solution and I didnt think this will work. But it did. Thanks – shoan Jun 26 '20 at 09:37
  • this worked for me as well. I tried deleting pods, podfile.lock, .wcworkspace, installing a newer version of cocoapods, I've tried it all and only this worked. Thank you ! – Raica Dumitru Cristian Sep 22 '21 at 14:51
20

Press Command+Option+Shift+K and then Run your app, you will see a magic.

Or from the menu -> Product, press Option on your keyboard and you'll see Clean Build Folder.

It's looking funny that how could Xcode do those things with us but same thing happened to me when I used a Swift library using Pod and after too much struggle I ended up with Clean Build Folder.

Yash Vyas
  • 558
  • 4
  • 24
  • 1
    Of all the hundreds of solutions out there for the 'No such module' error after installing pods in an Xcode project, this is the only one that actually works for me. +1. – instanceof Jan 25 '18 at 10:18
  • Forgot about the age-old addendum where you switch something off and then on again and it works. SIGH. – SDG Apr 27 '20 at 15:49
18

Not sure if this would still be helpful for others. But, in my case, it ended up being a silly mistake of not referencing dependencies from the .podspec file.

We have an application with multiple internal libraries, and those libraries also have dependencies on each other - which we accounted for the in the Podfiles... but NOT in the podspecs.

So, even though our Podfiles had:

Application / Podfile

# Development Pods
pod 'ConsumingLibrary ', :path => '../ios-consuming-lib'
pod 'DependentLibrary1', :path => '../ios-library-one'
pod 'CommonCoreLibrary', :path => '../ios-common-core-lib'

ConsumingLibrary / Podfile

# Development Pods
pod 'DependentLibrary1', :path => '../ios-library-one'
pod 'CommonCoreLibrary', :path => '../ios-common-core-lib'

Needed to also call it out in the .podspec's:

ConsumingLibrary / ConsumingLibrary.podspec

  # TODO
  # Add here any resources to be exported.

  s.dependency 'DependentLibrary1', '~> 0.1.0-RC'

DependentLibrary1 / DependentLibrary1.podspec

  # TODO
  # Add here any resources to be exported.

  s.dependency 'CommonCoreLibrary', '~> 0.1.0-RC'

I think I wasted about 2 hours trying to figure out why I could build ConsumingLibrary & run tests, but as soon as I built the app, that consumed all three libraries - I kept getting:

No such module 'DependentLibrary1'

LowAmmo
  • 351
  • 2
  • 4
  • Two libraries are having a dependency on each other. Is it not going to give us circular dependency issue? I am currently facing this issue. Do you know how to resolve this? – Mohd Haider Jan 20 '22 at 10:45
  • @LowAmmo you are a godsend. This was exactly my issue. Thank you immensely!!! – Patrick Oct 18 '22 at 11:46
12

In my case it was because I opened xcodeproj instead of the correct xcworkspace.

ABCD
  • 7,914
  • 9
  • 54
  • 90
9

Had this issue, too. I noticed the folder in Pods/broken_framework_name for framework which produced an error was empty even after pod install or pod update. So, for me those steps helped:

  1. close XCode completely
  2. remove DerivedData
  3. remove Podfile.lock. Before doing it, make sure your pods are set to specific versions and it will not cause unwanted code updates
  4. run pod deintegrate
  5. remove .xcworkspace file
  6. probably optional step: I had general line use_frameworks! written before all targets, but included it also in target in which I had an error
  7. run pod install

After all steps I noticed missing framework files finally appeared back and build was working again.

Eridana
  • 2,418
  • 23
  • 26
  • Be careful with removing the Podfile.lock. If any pods aren't set to use a specific version you could end up updating all your pods and need to then refactor your project. This may be fine on new projects but for legacy projects it could mean spending a few extra hours updating your codebase. – Rob Barber Nov 07 '20 at 15:12
  • @RobB, thanks for the note, but removing Podfile.lock is too often operation and it must not ruin your codebase. It must never happen that pods versions in your Podfile are set so badly. It shouldn't update to next major/minor version without you to change it specially. – Eridana Nov 10 '20 at 10:35
  • I totally agree with you. However, that is the best case scenario. Most codebases I come across don't follow best practices and don't properly set those values. In a perfect world you wouldn't have to worry about it. – Rob Barber Nov 10 '20 at 20:05
  • Hm, yeah, here I agree. Added warning to the post. – Eridana Nov 12 '20 at 08:37
  • Removing the .xcworkspace file and then calling pod Install was the crucial step for me! – Florian Cremer Apr 27 '23 at 11:12
6

Try using pod update after pod install command which will solve problem of No such module. I just tried and it working fine.

Thanks, Ratneshwar

6

Those who working with multiple targets , please don't forget to add this line in pods

def shared_pods
    pod 'SSKeychain', '~> 0.1.4'
    pod 'INAppStoreWindow', :head
    pod 'AFNetworking', '1.1.0'
    pod 'Reachability', '~> 3.1.0'
    pod 'KSADNTwitterFormatter', '~> 0.1.0'
    pod 'MASShortcut', '~> 1.1'
    pod 'MagicalRecord', '2.1'
    pod 'MASPreferences', '~> 1.0'
end

target 'Target_Name' do
    shared_pods
end

target 'Target_Name_Two' do
    shared_pods
end
Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47
  • 3
    oh Boy, you saved my life. thank you ! Note : If you haven't done any pod modification since you created your targets, everything will work fine, until you perform a pod update, which just happen to me. – Keuha Feb 10 '20 at 09:49
2

Sometimes happens when you have an obj-c pod within a swift project (even when you use the use_frameworks! in the .podfile).

If you're sure the pod is installed and you are still getting No such module, try this:

  • Go to Pods project in Xcode
  • Pods
  • Right click on the affected pod
  • Show in finder

There should be a package file with .framework suffix. Create a folder Modules in it. In this folder create a file called module.modulemap with code:

framework module MODULE_NAME_HERE {
  umbrella header "MODULE_NAME_HERE.h"

  export *
  module * { export * }

  link framework LINKED_FRAMEWORKS_AND_LIBRARIES_THE_POD_NEEDS_HERE
  link framework "AdSupport"
  link "c++"
  link "z"
}

Rebuild and you should be ok.

Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84
2

As @jakub-truhlář wrote, the root issue is the missing module.modulemap file due to some concurrency issue mixing Swift and Objective-C libraries, but instead of creating those files manually, would be better to try multiple times cleaning the Derived Data and build your project. When the project is successfully built then commit module.modulemap files to your repository to avoid to lose those files for example changing the current branch.

codingspark
  • 99
  • 1
  • 2
1

I faced the same problem in a swift framework I developed. The framework had a dependency of git project and the framework itself added as a pod to my main project. So, ideally the dependency has been specified in podspec file and Podfile as well.

I didn't faced the problem when accessing through the my main project but when I open the framework standalone it was throwing "No such module" error.

The root cause is, the base configurations is set with the path which points towards my main project instead of the framework itself because I ran podinstall first in my main project and then in the framework project.

Eg: in the project file it was like 0091AB0C861D71C94ADD7240 /* Pods-myframework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-myframework.release.xcconfig"; path = "../../Apps/MyMainProject/Pods/Target Support Files/Pods-myframework/Pods-myframework.release.xcconfig"; sourceTree = ""; };

After doing the below mentioned fix, 4444F5B1B35F066E57F96782 /* Pods-myframework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-myframework.release.xcconfig"; path = "Pods/Target Support Files/Pods-myframework/Pods-myframework.release.xcconfig"; sourceTree = ""; };

To fix the error,

  1. Project file -> Configurations -> Set all the configurations set to none.
  2. Remove Pods folder and Podfile.lock.
  3. Run 'pod install' first in the framework project direcory and then do pod install in main project directory.
Arvind Abi
  • 39
  • 5
1

I get some warning when pod install: '... target overrides the FRAMEWORK_SEARCH_PATHS build setting defined in ...'.

Fix it and enjoy.

Reference: target overrides the FRAMEWORK_SEARCH_PATHS build settings.

misumisu
  • 51
  • 3
1

Another way this issue can manifest: if you have multiple targets with different platforms (e.g. iOS and watchOS) you need to make sure your podfile specifies the correct platform for each target. Otherwise Cocoapods might be building the right pod but for wrong platform, leading to the "no such module" error.

You can fix it just by specifying the correct platforms e.g.

# global platform
platform :ios, '11.0'

target 'My Framework' do
  use_frameworks!

  pod 'RxSwift', '~> 5.1'
end

target 'My Framework (watchOS)' do
  # override global platform for this target
  platform :watchos, '4.0'

  use_frameworks!

  pod 'RxSwift', '~> 5.1'
end
Max
  • 21,123
  • 5
  • 49
  • 71
1

i fixed it by check "Find Implicit Dependencies" to true. Go to Edit Scheme -> Build Tab -> set Find Implicit Dependencies = true.

and rebuild.

enter image description here

Asi Givati
  • 1,348
  • 1
  • 15
  • 31
0

Adding link "c++" in the framework module.modulemap file worked for me

0

I had this problem when I opened XCode and then selected the workspace of my project via file->open recent.

I found that I had two .xcworkspace files on my filesystem for the same workspace/project.

Opening XCode by double clicking on the correct .xcworkspace file did the trick. The correct one is the one that works.

I later deleted the wrong one.

Gerd Castan
  • 6,275
  • 3
  • 44
  • 89
0

I just updated particular dependencies in terminal

Go to project folder then run below command

pod update your pod name

For me I need to do

pod update ReachabilitySwift

karthikeyan
  • 3,821
  • 3
  • 22
  • 45
0

Had this issue while adding CocoaPods into an old project, which already had manually included libs from before. It happened because Xcode was not resolving to the Framework Search Path generated by CocoaPods because of values previously set in target's settings.

Solution that helped me:

  1. copy the old path

  2. hit delete to completely clear the Framework Search Path settings in the target's column - the path, generated by CocoaPods would appear there

  3. add the old search path back under the generated one (only needed if you still have some manually added frameworks to work with)

  4. Clean project, wipe Derived Data, build.

The result would look like this (1st line added by Xcode, 2nd added by CocoaPods, and 3rd is manual): enter image description here

Vitalii
  • 4,267
  • 1
  • 40
  • 45
0

In case of multiple targets. For eg. Target1, Target2

use_frameworks!

target 'Target1' do
 pod 'Fabric'
 pod 'Crashlytics'

   target 'Target2' do
   end

end

Then run pod install.

Yogendra Singh
  • 2,063
  • 25
  • 20
0

I tried all of these suggestions but nothing worked for me. Instead what'd worked for me was deintegrating pods. Afterwards deleting the pods folder from xcode hierarchy and doing pod install. Suddenly it worked. Don't ask me why because anyways most of these suggestions are hit or miss anyways but I'll be happy if it works for someone else too :)

0

Make sure to import correct framework name that is defined in .podspec of the pod.

Leo
  • 3,003
  • 5
  • 38
  • 61
0

My setup

  • macOS 10.14 Mojave
  • Xcode 10.3
  • cocoapods 1.7.5

None of the answers work for me, although some gave partial clues. In my case, the root cause was that I customized my build product paths after running pod install.

If you run cocoapods right after creating an Xcode project, then it usually works if you open the generated Xcode .xcworkspace instead of the .xcodeproj.

Funny things happen if you start tweaking your build product paths after generating the workspace. Because the generated Pods project and its target all refer to your old Xcode project settings.

In my case, my trouble came from:

  • I prefer all my build products sitting under the project folder $(SRCROOT)/build/$(CONFIGURATION)/$(EFFECTIVE_PLATORM_NAME). So I went ahead and changed my Pre-configuration Build Products Path to it .... AFTER doing pod install.

Now, the generated Pods project, including all its Framework target, still points to the old location, so both the header import and linking of your own project will fail (you'd see Command PhaseScriptExecution failed with a nonzero exit code when No such module is fixed).

The fix:

  • Delete all Pods stuff including the workspace.
  • Regenerate Pods project and workspace with pod install. However, cocoapods hardcodes the build product path to ${SRCROOT}/../build and Pre-configuration Build Products to $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) in my case, which usually points to a temporary ~/Library/Developer subfolder . Still not quite right. Then ....
  • Make sure the Framework Search Path and Header Search Path of my own project cover the above paths.
  • Tweak Pods project setting and all dependency Framework's Pre-configuration Build Products Path to use my preferred paths.

The moral lesson: Always regenerate Pods and verify the key result paths whenever you touch paths in Xcode project settings.

UPDATE

With Xcode 11, Apple finally removed the confusing "Pre-configuration Build Products Path". To customize the build product paths, use Locations in Xcode preferences with global relative paths pre-baked.

kakyo
  • 10,460
  • 14
  • 76
  • 140
0

I usually remove Pods folder and .xcworkspace file, then I run pod installagain and it helps in almost 100% cases.

0

If you see this warning:

[!] The `Joint [Debug]` target overrides the `FRAMEWORK_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-Joint/Pods-Joint.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `Joint [Release]` target overrides the `FRAMEWORK_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-Joint/Pods-Joint.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

follow the instructions to avoid Module not found issue.

cora
  • 1,916
  • 1
  • 10
  • 18
0

For me, removing the following from my podFile fixed it:

      installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
-3
  • clean project
  • close xcode
  • open xcode
  • enjoy
Ivan
  • 1,320
  • 16
  • 26
-6

For using Swift in Objective-C, you should import a header file that Xcode generates automatically in compile time (NameOfModule+Swift.h). In this case, you should try import SwifityJSON in you header file like this:

#import "SwiftyJSON-Swift.h" 
Allan Scofield
  • 1,884
  • 18
  • 14
  • 2
    `use_frameworks!` you don't need to import the `Obj-C` header, you import the module, also the OP is using swift where do you see the need to import into `Obj-C`? – sbarow Mar 21 '16 at 15:26