Swift import module - ios

I am new to developing iOS apps, so I'm still on the learning curve and I am experiencing quite a strange problem.
I have a project in which I am using the "Alamofire" module with CocoaPods. Everything is fine and working so far. Then I created another controller in which I want to import the same module, but the resulting message is always "No such module..."
How and why is it working in one file, but does not work in the other? Both files are in the same directory.
P.S. I've tried cleaning the project and also deleting the "DerivedData" folder of Xcode.

Check your both files Target Membership. It needs to be set to the target you are using:
Likely, it seems you dragged file into your project and did not set target properly. Check it twice, because there is no other reason for that. Unless your second file is in Test target. In that case add to your pod file:
target 'YourTestTarget' do
pod 'Alamofire'
end
and run pod install

Related

Swift Build Error - No such module 'Feature1'

I am getting compile error when I added a framework into my app. Framework Feature1 is built successfully but from module App import is not working.
How to solve this issue?
There are several potential misconfigurations the issue can arise for,
Please confirm that you have opened the .xcworkspace but not .xcodeproj file. Also make sure you have build Feature1 first before you build App.
Make sure that iOS Deployment Target is set same for all modules with App. For example is Apps deployment target is set to 9.0, Feature1s deployment target also need to be set to 9.0.
Make sure your main module (App) and your used framework (Feature1) have same set of configurations. i.e. If your Project has three configurations, Debug, Release, ReleasePremium than your Framework also need to have three configurations Debug, Release, ReleasePremium. Also make sure that the archive configuration is set same for both App and Feature1. i.e. if your Apps archive scheme is set to ReleasePremium, your Fearure1s archive scheme also need to be set into ReleasePremium.
Please assure that you do not need to import Feature1 in each .swift files when its already added in the Bridging-Header.h.
In case of issue came from Pod files, make sure you have uncommented #use_frameworks! into use_frameworks! from you Podfile. Sometime re installing pod works if Feature1 has any dependency on pods.
If none of the above steps works, delete your derived data folder and try re building.

All Pods not recognized after starting the process of adding to app store 'No such module' error

My app worked just fine until I started the process to upload to the app store and somewhere during that process, I started getting the error 'No such module'.
I have tried different pods, same result
I have tried a new blank project with just the import line (after importing the pod), same result
After eliminating the pod it self and the project, it has got to be a setting that got changed that won't allow it to see the pod files. If anybody has any thoughts, I would be greatly appreciative.
*edit: Taking Dershowitz123's advice, I have tried changing the path for the frameworks to
$(SRCROOT)
screenshot1 (sry, I don't have the reputation to post embedded images yet).
I still get a failed build, but I think you are in the right direction. I noticed that it isn't finding the framework file.
screenshot2
I've looked for the file listed and I don't see one in the directory anywhere. When I made my blank test project, it also didn't create a Pods_RiskAssement.framework file (or similar named file).
*edit 2
here's my Podfile:
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!
target ‘RiskAssement’ do
pod ‘SimplePDF’
end
*edit
Resolution. I was unable to figure out how to import the pod, but was able to copy the swift file data and embed it directly into the code for my app. This way I didn't need to reference the pod and was able to build the app.
I'm not sure why this is actually happens, but one way to solve your issue is to go into your build settings and defining the Framework Search Paths to a folder which contains the frameworks in question. If the frameworks are placed in your project directory, simply set the framework search path to $(SRCROOT) and set it to recursive.
I recently received the same 'No such module' message for the different PODS that I had installed. The resolution for me was to select the PODS project in my workspace, select all of my targets, and then manually build them using either the menu command or the Command B shortcut. After it finished building the errors went away.
I hope it helps!

Xcode 7.3 Syntax Highlighting and Code Completion issues with Swift

I am having an extremely frustrating issue with XCode 7.3 (however, this issue has persisted since I installed XCode 7.2) and Swift code, and I am hoping others have had this issue and know how to resolve it. Syntax highlighting and code completion work perfectly fine in Objective-C files, and also works fine when calling other Swift objects within Swift code. However, any Objective-C objects or methods mentioned in Swift code get no syntax highlighting, and XCode will not complete ANY Objective-C declared methods or properties. Everything compiles and runs just fine.
I should also add that I have also tried doing a completely clean install of XCode. I deleted all my derived data, deleted all XCode caches, and deleted my XCode preferences files (in addition to obviously deleting the XCode.app archive before re-installing).
It is making it extremely difficult to develop in Swift. I don't want to do this, but if I can't find a way to resolve this I'll be forced to go back to using Objective-C.
I have the same problem. But finally solved it.
I make two change, not sure which is the key point but you can try them all.
delete the module cache
Within the same folder as your project's Derived Data is a Module
Cache. When Code Completion stopped working, deleting this fixed it.
Close Xcode and delete the
~/Library/Developer/Xcode/DerivedData/ModuleCache directory.
change the Enable Modules value
Go to the Build Settings of your target, then search Enable
Modules
If it's Yes, change it to No, and you may get some build
error, just change it back to Yes.
After two steps above you should Clean(Shift+Command+K) your project.
For now you may fixed the problem.
So it seems the issue was with CocoaPods. I was using Cocoapods as a static library instead of as frameworks. Switching to frameworks (using use_frameworks! in my Podfile) and importing the libraries into Swift has resolved all my issues. I'm guessing all those third party library headers were just too much for XCode to process. Either way, the issue is now resolved. I hope this helps someone in the future.
This might not be necessary anymore but i still want to post this:
At the time of this post, the most recent version of cocoapods (1.0.0.beta.8) requires you to define pods for each Xcode target.
In my case I had a class compile for the project target and for a testing target. I added a pod only to the main target, because of laziness.
Now working in the code of class A I added the pod framework using import NAME and tried to use the classes of the framework. Xcode wouldn't highlight the particular code where I use the new classes, but compiling and running works fine. In the completion dialog the type of the variable was <<error type>>
The way to resolve this issue: in the Podfile add the newly added pod to all targets, the class A is member of.
Now Xcode finds the necessary frameworks for all targets and code highlighting works again.
EDIT 1:
A possible solution is defining a list of shared pods, like in my example:
platform :ios, '8.4'
use_frameworks!
inhibit_all_warnings!
def all_pods
pod 'MPMessagePack'
pod 'SwiftyDispatch'
pod 'BFKit'
pod 'Timepiece'
pod 'Alamofire'
pod 'AlamofireSwiftyJSON'
end
def testing_pods
pod 'Quick'
pod 'Nimble'
end
target 'App' do
all_pods
end
target 'AppLogicTests' do
all_pods
testing_pods
end
target 'AppUITests' do
pod 'RxTest'
all_pods
testing_pods
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end
This will add all pods to all targets and adding all testing pods to the targets. Next to these I added 'RxTest' to the AppUITests.
(Chosen pods are examples of my projects, no advertising intended :-) )
We had the same issue in a mixed ObjC/Swift project. Tried all the suggestions about deleting derived data etc, to no avail. Sometimes it helped, but not in a reproducible way and after some time it stopped working.
The post of Galvin in this post put me on the track of the Module related build settings. However it was another setting that solved the code completion/coloring in a reproducible way: setting DEFINES_MODULE (under Packaging) from YES to NO for our main project was the solution.
Notes:
I expected this to break the ObjC/Swift interoperability in our project, but that still works. It seems that setting is only to be used for framework targets. (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html)
This project setting has not been changed for months, but the code completion issues came up only recently, both for my colleague and me.
If none of the above worked for you and you're using Cocoapods, you can try switching to Carthage.
I tried every suggestion I could find on Google to no avail. But consistently Cocoapods seemed to be coming up as a reason with many hacks in attempt to fix it. I have been reading up on Carthage, and how it doesn't modify your project, force you to use a workspace, or potentially fill your build folder with header files (which confuses Xcode and can cause the syntax highlighting and autocomplete to break).
After making the switch I haven't run into any issues yet, and to be honest I prefer the teensy bit of overhead to have a clean solution. This post really drove it home for me.

How to get cocoa pods to work?

I have installed cocoapods. I've done everything that I've seen online, yet I can never successfully import a 3rd party framework into my project. I have tried many, many times--at least 20 probably, and have not once been able to successfully do this. Take for example, this library: https://github.com/uacaps/PageMenu
I added the podfile, I ran "pod install", that worked, I opened up the workspace and not the original project, I added the framework under "linked frameworks and libraries." But it still says "No such module Page Menu." It does this for every single pod that I try to install. What am I doing wrong? From what I've read everyone seems to think they are so easy to install. And they are, problem is they just never work once I do install them. Is there some missing step that everyone else knows about that I don't? I have looked under build settings and I've read something about changing the linker flags, but I couldn't figure out how to do that. I have tried installing the library manually and that didn't work either. Could it be that something is just wrong with my Xcode? I've been having this problem for a few months, and it has stayed consistent since I updated my Xcode recently. Does anyone have any idea what this could be?
edit: link to Podfile photo:
http://i58.tinypic.com/2lc2zqb.png
First,make sure that you have something like this in your PodFile (same folder as your xcode proj)
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'PageMenu'
then cd to the directory and do pod install in terminal.
I am assuming that you are using swift. Build the project. Go to your report navigator.
EDIT:: Do open the proj using xcworkspace instead of xcodeproj
You should see something like this.
This tells you what you have to add in your bridging header.
To create a bridging header, create a random objective c file (with cocoa touch class). XCode will ask you if you want to create bridging header.
Select yes, then delete the files you just created. Next, go to the generated bridging header file. Add in
// this header should be based on the name you see in report navigator.
#import <PageMenu/PageMenu-Swift.h>
Look, Calm Down..
I had the same problem.Didnt give up.try doing this as well,worked for me
create new project
close xcode
go to target folder pop init
open -a Xcode Podfile-uncomment platform -pod 'PageMenu' ( I typed this outside target this time/not like the usual way typing it inside target- do/ ,save and close)
open xcodeworkspace and Type - import PageMenu -( still says unresolved module )
Now Build ..
(worked for me, It somehow works with clean or Build i suppose ,so try both)

"No such module 'Alamofire'" won't recognize framework

I am trying to add Alamofire to a new XCode project with Swift. I feel like I have tried everything.
Every time I try to add
import Alamofire
I get "No such module".
I have tried installing it as stated on https://github.com/Alamofire/Alamofire,
I tried doing it manually first, then Carthage and Cocoapods, but with the same result.
I have tried deleting the DerivedData folder and rebuilding the project without any luck.
It is a completely clean install, yet it just won't recognize the framework. I have tried the suggestions in the first 10 Google searches and here on Stackoverflow (Cannot install Alamofire in new Xcode Project. "No Such module Alamofire") Here are some screenshots from my latest manual attemp:
Looks like you are using the module by directly dropping the source files into your project.
If that's the case, you don't have to use import Alamofire header or use Alamofire( dot ) in the beginning of every method.
Just use the code as below omitting Alamofire tag.
request(.GET, "https://httpbin.org/get")
I know it's late answer, but I was facing same problem with Xcode 8 Swift 3.0. I follow this Alamofire link and added framework manually. Its working fine. One of my project stuck on 'no such module' error, I cleaned derived data (Cleaning derived data removed source files of Alamofire. I added it again in my project ;) ) and it works like charm :).
Followed instructions
Download Alamofire
Drag Alamofire project in your project directory
Check alamofire deployment target same as your project
Go to your project general settings, click on the + button under the "Embedded Binaries" section.
You will see two different Alamofire.xcodeproj folders each with two different versions of the Alamofire.framework nested inside a Products folder. It does not matter which Products folder you choose from, but it does matter whether you choose the top or bottom Alamofire.framework.
Select the top Alamofire.framework for iOS and the bottom one for OS X.
And that's it! The Alamofire.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
same error here.
I solved the problem by the following steps:
Click on your project (targets)
Click on Build Settings
Under Search Paths-Framework Search Paths, add the directory path which contains Alamofire.framework
Hope this can solve your problem!
I was importing Alamofire and I ran into the same issue. Turns out the Cartfile was not in the same folder as the .xcodeproj file.
Once I moved the Cartfile, the Cartfile.resolved files and the Carthage folder to the same folder as the .xcodeproj file my project didn't trigger any errors.
Make sure to also add this line to Build Settings > Framework Search Paths:
$(PROJECT_DIR)/Carthage/Build/iOS
I was able to resolve this issue changing my Podfile. I originally had the reference to Alamofire in a target:
The problem disappeared when I changed the podfile to the following:
platform :ios, '8.0'
use_frameworks!
pod 'Alamofire', '~> 3.0'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
target 'xxxxxxx' do
pod 'GoogleMaps'
end
target 'xxxxxxxTests' do
pod 'GoogleMaps'
end

Resources