I’m currently using Realm in one of my projects, where I manually installed it. Everything was working fine until I updated Xcode from 10.1 to 10.2. Now I keep getting the following error.
Module compiled with Swift 4.2 cannot be imported by the Swift 5.0 compiler: /Users/userName/MyApp/RealmSwift.framework/Modules/RealmSwift.swiftmodule/i386.swiftmodule
I believe this has to do with the fact that when I try to replace the Realm frameworks in my project with the newest Realm compiled for Xcode 10.2, Xcode doesn’t copy the files, it just references them even when having the Copy Files If Needed option checked.
Anyways, I now would like to try using Realm through Cocoapods to eliminate this kind of issues every time I update Xcode, so my questions are…
What do I need to change in Xcode in order for me to move from manual install to use Realm through Cocoapods?
What do I need in Framework Search Paths?
Do I need to remove the Run Script Phase
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"?
What do I need in my Pod file? I’m more interested to see how I would incorporate Realm for my WatchApp Extension since I couldn’t find any info in the documentation.
Here is how my Pod file looks like right now.
Pod File
#platform :ios, '9.3'
target 'MyApp' do
use_frameworks!
# Pods for MyApp
pod 'Firebase/Core'
pod 'NVActivityIndicatorView'
target 'MyAppTests' do
inherit! :search_paths
end
target 'MyAppUITests' do
inherit! :search_paths
end
end
target 'MyApp Watch App' do
use_frameworks!
end
target 'MyApp Watch App Extension' do
use_frameworks!
end
FYI - I’m already using Cocoapods in my project but not for Realm yet. Also, I’m using Realm for iOS and WatchApp Extension in this project.
If you already have the workspace created by cocoapods, you don't need to modify your project settings, when you add a new pod to your podfile, cocoapods will automatically handle linking that to your project correctly.
Simply remove the manually added Realm framework files, remove the custom Run Script build phase containing "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh", then run pod update and you should be good to go.
As for the original issue of
Module compiled with Swift 4.2 cannot be imported by the Swift 5.0 compiler: /Users/userName/MyApp/RealmSwift.framework/Modules/RealmSwift.swiftmodule/i386.swiftmodule
, when using precompiled frameworks, you need to wait until the developer of the framework updates the precompiled versions for Swift 5 (or the newest version you want to switch your project to) before you can use them.
Since cocoapods compiles all dependencies from source on your own machine, this issue of incompatible Swift compiler versions cannot arise and you can even control which Swift version to use for each project specifically from your podfile.
Related
I am trying to implement UITests in an application I'm working on.
When I am in my UITests.swift file and I try to run the app from a test, Xcode gives the following error for some of the pods I'm using:
Command CompileSwift failed with a nonzero exit code
It gives this error for a bunch of pods that are compiling just fine when running the regular project:
My PodFile looks as follows:
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
source 'https://github.com/cocoapods/specs.git'
project 'Project.xcodeproj'
use_frameworks!
# Define all thirdparty pods we need
def thirdparty
pod 'Moya', '~> 11.0'
pod 'Alamofire'
pod 'SwiftyJSON'
pod 'Differ'
.. a bunch of other pods
end
# Pods for Project project
target 'Project' do
thirdparty
end
# Pods for ProjectTests
target 'ProjectUITests' do
thirdparty
pod 'Nimble'
end
I'm having a hard time reasoning why this is happening, as my project normally compiles just fine. Other posts on S.O. regarding this problem report that the problem also occurs when building the project rather than just running for a test
Question How can I make sure that all pods I use in my project, also compile correctly when building from a UITest?
How can I make sure that all pods I use in my project, also compile correctly when building from a UITest?
The only way to know whether something will build or not is to try to build it. So when you change your CocoaPods configuration, even if that's just to update to a newer version of one or more pods, you need to try building each target.
target 'ProjectUITests' do
thirdparty
pod 'Nimble'
end`
According to your Podfile, you've got the pod Nimble being used only in the ProjectUITests target. If that's the only target that fills to build, then it seems likely that that pod is the culprit.
Except for one case (at least as far as you've shown) your Podfile doesn't specify versions for the various pods that it specifies. If you leave out the version for a given pod, your project will use the latest available version. That means that anytime you update your pods you'll pull down the latest version, even if that new version contains breaking changes. It would be safer to specify the version that you know works, or at least to limit the version to minor version and patch updates, like:
pod 'Nimble', '~>7.0'
That will let CocoaPods automatically use the latest version up to but not including 8.0. If the pod developer properly follows the semantic versioning scheme, that should ensure that you don't inadvertently pull in any breaking changes.
The problem is that target :AppModuleTests do do not have an app host and you are using inherit! :search_paths. This means that this target would find the dependencies to load them from the host but in this case there is none.
target TestApp do
pods
target :AppModuleTests
end
This worked for me.
My project in Xcode consist of static frameworks and one custom dynamic framework. This dynamic framework includes some other static frameworks.
When I try to compile the custom dynamic framework itself, everything is fine. I was able to force to install latest version of frameworks (Alamofire, Realm, etc..) by forcing the pod definition file
platform :ios, '9.0'
But when I compile my project even when I use the above line, I am getting the old frameworks.
When I try to force the pods for a explicit version,
pod 'Alamofire', '~> 4.4.0'
getting the version 3.5.1.
Is there any other explicit setting to force CocoaPods to be more accurate in versions?
Originally the project for the dynamic framework was made for the Swift version 2.3, which is actually requiring the version of Alamofire 3.5.1.
Any help will be appreciated.
Maybe try the following in your podfile:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '4.4.0'
That will bypass your local spec repo and get straight from git.
Which version of CocoaPods you have currently installed on your machine? Which version was used to originally establish Pods in project? I've spotted an issue when I updated CocoaPods, that pod update hasn't been working properly, and removing just Podfile.lock and Pods/ directory wasn't sufficient to make things right.
That said I would do the following:
update CocoaPods to newest version
pod repo update for newest Pod specs
pod deintegrate to completely remove Pods from project
pod install to re-create Pods in the project
The solution is kinda tricky. I haven't realise in the beginning that the pods under a dynamic framework cannot actually be executed directly from top project and there is a configuration JSON file, which actually is managing the pods under the dynamic framework.
So the pod versions were actually hardcoded there.
I have an objective C iOS app using the Parse SDK.
In the process of moving this app from Parse.com to a self hosted Parse-Server, I need to update the Parse SDK to the latest version. For this update I decided to go with CocoaPods.
This is the first time I touch CocoaPods (after reading and hearing so much good about it).
I found my way, following what I could read here and also based on a few CocoaPods tutorial I quickly viewed.
Having my project "ready", when buiding it I get this error:
#import <ParseUI/ParseUI.h> -----> File not found.
Obviously things have changed place. And I tried a couple of unsuccessful solutions.
So here is my question:
How do I need to change the settings of my project, now that I am using CocoaPods?
In order to use Cocoapods with parse and Parse UI you need to do the following steps:
Create a new file and name it Podfile. This file should be located on your IOS project root folder.
The Podfile should contain at least the following structure if you want to use parse IOS SDK and ParseUI
platform :ios, '8.0'
use_frameworks!
pod 'Parse'
pod 'ParseUI'
# Put more pods in here..
Notice to the platform, you may change it to the minimum version that your app can run on and the use_frameworks! will install all your pod as frameworks and this is mandatory if you like to consume Swift libraries.
Open terminal and navigate to your IOS root directory and enter pod install. This command will install all the pods and dependencies into your project.
After installing you will no longer use the IOS project file from now on you will use a new file which called workspace. The workspace will contain both your project files and the pods project/frameworks files.
Build your project, fix some error (if there are) and run it to make sure that it works as expected .
More CocoaPods commands that you need to know are:
pod update - update all your pods to the latest release or to the release that was mentioned in the Podfile
pod update update specific pod to the latest release or to the release that was mentioned in the Podfile
pod outdated - display out to date pods that are being used inside your project.
In Xcode 8 I'm having trouble importing any Swift 2.3 or 3 framework that was added with Cocoapods into my project.
There is a public umbrella.h file, but for some reason Xcode can't find the framework when I try to #import it.
As an example, create any Objective-C project, use the following Podfile, pod install, and then try the #import. It asks me to update the code to swift 2.3 or 3 even if that code is already Swift 2.3 or Swift 3 code. I've cleaned and tried to rebuild as well.
platform :ios, '8.0'
use_frameworks!
target 'testingFrameworks' do
pod 'SwiftyJSON'
end
Did I miss a step?
I used socketIO and was having the same problem. My solution to this is:
Close project.
Delete pod files, delivered files, pod framework, workspace file (clean up project)
pod install
Reopen workspace, upgrade swift syntax if xcode ask for, build a few times.
You might need to fix something for the new swift.
I have two swift projects, application and library, where library is a dependency of application. I have a Podfile configured as so;
workspace 'myworkspace'
platform :ios, '9.0'
use_frameworks!
target :library do
project 'library/library.xcproject'
pod 'GCDWebServer', '~> 3.0'
target :application do
project 'application/application.xcproject'
end
end
After running pod install successfully, I open myworkspace in Xcode, and find application as the currently selected scheme. Immediately building results in failure, due to;
No such module 'library'
To solve this I need to change the current scheme to library, build, then switch the scheme back to application and it will successfully build.
Questions;
Is this expected, or a bug in xcode and/or CocoaPods, or have I configured something incorrectly?
Does this mean I need to separately build library anytime library source changes occur to reflect those changes in application builds?
Xcode 7.3, CocoaPods 1.0.1, repo
Try do the followings:
1.Open the 'xxx.xcworkspace' file to run your project. Do not open 'xxx.xcodeproj' to run your project again.
2.Product->Clean->Run
3.Add all the pod targets to 'Linked Frameworks and Libraries' in Project -> General