CocoaPods
iOS Development
Xcode
Swift
Dependency Management

'No such module' when I use CocoaPods

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The Xcode error No such module after adding a pod usually means the dependency was not integrated into the build configuration Xcode is actually using. The fix is usually not in Swift source code, but in the workspace, target settings, Pod installation, or stale build artifacts.

Start with the Correct Project File

After running CocoaPods, you should normally open the generated .xcworkspace file, not the original .xcodeproj file. The workspace includes both your app target and the Pods project, which is how Xcode finds the installed modules during compilation.

Typical setup commands are:

bash
cd MyApp
pod install
open MyApp.xcworkspace

If you keep opening .xcodeproj, the pod may exist on disk while the compiler still reports No such module because the Pods project is not loaded.

Confirm the Pod Is Installed for the Right Target

A common configuration mistake is putting the pod in the wrong target block inside the Podfile.

ruby
1platform :ios, '15.0'
2
3use_frameworks!
4
5target 'MyApp' do
6  pod 'Alamofire'
7end

If the pod belongs to MyAppTests or another target but your main app imports it, the module will not be available where you expect it. After editing the Podfile, rerun:

bash
pod install

Then rebuild the workspace.

Clean Derived Data and Rebuild

Xcode sometimes keeps stale build information even after pods are installed correctly. A clean rebuild is often enough to clear the error.

bash
rm -rf ~/Library/Developer/Xcode/DerivedData

Then in Xcode:

  1. close the workspace
  2. reopen the .xcworkspace
  3. build again

This is especially useful after changing Swift versions, renaming targets, or switching branches.

Check Framework Integration Settings

If the workspace is correct and the pod is installed, look at how the target links frameworks. Problems here are often caused by manual project edits, old Podfiles, or target inheritance issues.

Useful checks include:

  • the pod is listed in the correct target section of Podfile.lock
  • the build uses the generated Pods configuration files
  • '$(inherited) appears in relevant build settings'
  • the app target and pod support the same platform and architecture

If the pod uses frameworks, use_frameworks! or the appropriate linkage setting may be required depending on the dependency.

Example Import

A correct integration should let you import the module directly in Swift.

swift
1import UIKit
2import Alamofire
3
4final class ViewController: UIViewController {
5    override func viewDidLoad() {
6        super.viewDidLoad()
7
8        AF.request("https://httpbin.org/get").response { response in
9            print(response.response?.statusCode as Any)
10        }
11    }
12}

If this import fails even though CocoaPods reports success, the issue is almost always in project integration rather than the Swift file itself.

When Architecture or Version Mismatch Is the Real Problem

Some pods do not support every Xcode version, Swift version, or Apple platform combination. The error can surface as No such module even though the deeper cause is an unsupported build target.

That is why checking the pod's README, supported iOS version, and recent release notes matters. On Apple Silicon machines, simulator architecture settings can also expose integration issues that did not appear on older Intel setups.

Common Pitfalls

  • Opening .xcodeproj instead of .xcworkspace is the most common CocoaPods integration mistake. Always build from the workspace after pod install.
  • Adding the pod to the wrong target in the Podfile leaves the intended app target without the dependency. Verify the target block carefully.
  • Changing the Podfile without rerunning pod install leaves the workspace out of sync with the declared dependencies. Reinstall after every meaningful Podfile edit.
  • Ignoring stale Derived Data can make a fixed configuration still look broken. Clean the build artifacts when troubleshooting persists.
  • Assuming every pod supports your current Xcode, Swift, and platform combination can hide a version-compatibility problem. Check the pod documentation when integration looks correct but compilation still fails.

Summary

  • 'No such module with CocoaPods is usually an integration problem, not a Swift syntax problem.'
  • Open the .xcworkspace, not the .xcodeproj.
  • Make sure the pod is installed under the correct target and rerun pod install after changes.
  • Clean Derived Data when Xcode keeps stale module state.
  • Confirm the pod actually supports your toolchain and target platform.

Course illustration
Course illustration

All Rights Reserved.