"No such module" error in Xcode 8 - ios

I get the "No such module" compilation error in Xcode 8.2.1 in my Swift project. I use Carthage with two modules: Alamofire and Fuzi. The Carthage/Build/iOS directory exists with the two framework files. The Build Settings/Framework Search Paths points to that directory. I have embedded the two framework files in General/Embedded Binaries. What am I missing?

You shouldn't need to embed the libraries; they should be added to Linked Frameworks and Libraries underneath the "General/Embedded Binaries" section. Make sure you have the Carthage copy-frameworks script added to your Build Phases.
From the Carthage documentation:
On your application targets’ “General” settings tab, in the “Linked
Frameworks and Libraries” section, drag and drop each framework you
want to use from the Carthage/Build folder on disk. On your
application targets’ “Build Phases” settings tab, click the “+” icon
and choose “New Run Script Phase”. Create a Run Script in which you
specify your shell (ex: bin/sh), add the following contents to the
script area below the shell:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input
Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Box.framework
$(SRCROOT)/Carthage/Build/iOS/Result.framework
$(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
This script works around an App Store submission bug triggered by
universal binaries and ensures that necessary bitcode-related files
and dSYMs are copied when archiving.

Firstly you check Carthage installed or not in your machine like the following command in your terminal
carthage version
If carthage is not installed in your machine try the following.
Download the latest release of Carthage, and double-click Carthage.pkg to run the installer. Click Continue, select a location to install to, then click Continue again, and finally click Install.
Then you can check carthage version.
If you are using existing project then move to project folder like
cd ~/Path/To/Starter/Project
Try the following command for update cartfile
carthage update —platform iOS
After installation/updation completed then try the following command
open carthage
You should see a Finder window pop up that contains two directories: Build and Checkouts.
In the Carthage Finder window, navigate into Build\iOS. Now, drag Alamofire.framework(for example) into the Linked Frameworks and Libraries section in Xcode:
Next, switch over to Build Phases and add a new Run Script build phase. Add the following command:
/usr/local/bin/carthage copy-frameworks
Click the + under Input Files and add an entry for each framework:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework

Related

Library not found for -lRNAppleAuthentication react-native iOS

I have tried deleting "$(inherited)" in library search paths and but it's not working
Have a try with the below solution.
You can go to File > Workspace Settings if you are in a workspace environment or File > Project Settings for a regular project environment.
Then click over the little grey arrow under the Derived data section and select your project folder and close the workspace and Xcode then delete the project directory from the derived data directory.
Open the workspace again in Xcode and clean and rebuild the project.
Also, make sure that you have applied pod install after the package installation.

How to edit or install the framework file in Xcode via Carthage?

How can I edit or install the framework swift file in Xcode via Carthage?
In this screenshot only have 2 file, Why? How to install the swift file in it? So that I can modify it.
What I want to do is change some code in PieChartRenderer.swift. What I want to modify: Here is the link
File location:
Carthage > Checkout > Charts > Source > Charts > Renderer > PieChartRenderer.swift
I followed Usage on the README.md. I have completed this 4 step.
Drag the Charts.xcodeproj to your project
Go to your target's settings, hit the "+" under the "Embedded Binaries" section, and select the Charts.framework
#import Charts
(Xcode 8.2+) Under "Build Options", mark "Always Embed Swift Standard Libraries"
Current problem: I Dragged the Charts.xcodeproj from Checkout to my
project. The code is work when I run it on stimulator. But when I stop
it and open it again, the value line show up again. On real device,
the modified code is no effect... Why?
Sorry, I'm new in Carthage.
The source is under the Carthage folder: Carthage/Checkouts/Frameworkname/source
1 cd [project_name]
2 carthage build --no-skip-current
https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#carthagebuild

What's the equivalent of "development pods" under Carthage?

The teams developing frameworks for our iOS app are migrating from Cocoapods to Carthage.
Under Cocoapods, I could set up dependencies as "development pods". For example, instead of having the main app download a specific version of an xyzzy dependency, I could set up xyzzy as a development pod and point it to my local directory where I had checked out xyzzy from its Git repo. While I was working in the main app's project, any edits I'd do to xyzzy's files would be made in that directory. This let me build and test changes immediately, and when I was ready to check them in, Git would find them in the xyzzy project's directory.
Under Carthage I haven't found a way to do this. I see http://allocinit.io/ios/debugging-carthage-dependencies/ which explains how to create symbolic links so that I can see the dependency source files to make debugging easier, but any edits I make to them are under the main application's Carthage/Builds directory.
How do I set up the equivalent of development pods under Carthage?
I believe Carthage doesn't have something similar to "development pods" yet.
But you could simulate "development pods" just following these steps:
Steps:
Add the .xcodeproj to your workspace
Remove all the dependencies you have in your project of the framework you added in step 1. (probably you may need to remove it from Build Phases -> Run Script -> Input Files too )
Go to General tab of the target you want to run, add the framework under Linked Frameworks and Libraries (it is going to take the one added from the .xcoproj)
(optional) you may need to run carthage bootstrap in the framework's repo you want to add locally.
That's it.
After that you will be able to run your project and update framework's code in the same workspace.
This works just as well as development pods for me, as of Xcode 8.3.3 and Carthage 0.24.0:
In app path, rm -rf Carthage
Point at the appropriate branch or tag in Cartfile
carthage update --use-submodules (generates .gitmodules and clones repo into Carthage/Checkouts)
In Xcode under project -> Build Phases -> Run Script, comment out the line that ends with carthage update --cache-builds if present.
Change to the General tab and remove the lib from Embedded Binaries
Right-click project, Add Files to app..., add lib from Carthage/Checkouts
Under project -> General, re-add the library, choosing the one you added in the previous step.
App should now build with the local lib. Make sure that your .gitignore has Carthage/{Build,Checkouts} and .gitmodules.
This answer is a summary of a successful implementation of the solution introduced here.
A cleaner solution is using local paths for dependencies in Cartfile.
Environment
Xcode 10.1
macOS 10.13.6
Step 1. Symbolic linking
1.1 Change $(SRCROOT_MAIN)/Carthage/Checkouts/$(DEVELOPING_FRAMEWORK_NAME) directory to a symbolic link pointing to source root directory of your developing framework $(SRCROOT_DEVELOPING_FRAMEWORK), where $(SRCROOT_MAIN) is source root directory of your main app. Backup existing directories before this change.
This linking enables version-controlled changes in your developing framework.
Syntax when using ln utility,
$ ln -s "$SRCROOT_DEVELOPING_FRAMEWORK" "$SRCROOT_MAIN/Carthage/Checkouts/$DEVELOPING_FRAMEWORK_NAME"
1.2 Change $(SRCROOT_DEVELOPING_FRAMEWORK)/Carthage/Build directory in your framework to a symbolic link pointing to $(SRCROOT_MAIN)/Carthage/Build directory. Backup existing directories before this change.
This linking enables access to all frameworks built by Carthage from both your developing framework and your main app.
Syntax when using ln utility,
$ ln -s "$SRCROOT_MAIN/Carthage/Build" "$SRCROOT_DEVELOPING_FRAMEWORK/Carthage/Build"
Step 2. Framework Replacement

2.1 Remove your developing framework in Xcode > YOUR_MAIN_APP > General > Linked Frameworks and Libraries (that is, the one located in $(SRCROOT_MAIN)/Carthage/Build/iOS).
2.2 Add $(DEVELOPING_FRAMEWORK_NAME).xcodeproj (found in directory pointed by $(SRCROOT_MAIN)/Carthage/Checkouts/$(DEVELOPING_FRAMEWORK_NAME) symbolic link) into your main app
2.3 Build the developing framework product for device and simulator
2.4 Add the new developing framework auto-detected by Xcode in Xcode > YOUR_MAIN_APP > General > Linked Frameworks and Libraries.
2.5 Add $(DEVELOPING_FRAMEWORK_NAME).framework as a target dependency by adding $(DEVELOPING_FRAMEWORK_NAME).framework in Xcode > YOUR_MAIN_APP > Build Phases > Target Dependencies.
2.6 Copy $(BUILT_PRODUCTS_DIR)/$(DEVELOPING_FRAMEWORK_NAME).framework to $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/$(DEVELOPING_FRAMEWORK_NAME).framework by adding a new input file $(BUILT_PRODUCTS_DIR)/$(DEVELOPING_FRAMEWORK_NAME).framework and a new output file $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/$(DEVELOPING_FRAMEWORK_NAME).framework in Xcode > YOUR_MAIN_APP > Build Phases > Run Script of Carthage Embed Framework.
Reference
Debugging Carthage Dependencies
https://allocinit.io/ios/debugging-carthage-dependencies/
Build Setting Reference
https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html

Where is the Run Script and Build Phase in Xcode?

To get Carthage set up, the documentation says that you need to add a Run Script.
On your application targets’ “Build Phases” settings tab, click the
“+” icon and choose “New Run Script Phase”. Create a Run Script in
which you specify your shell (ex: bin/sh), add the following contents
to the script area below the shell:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input
Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Box.framework
$(SRCROOT)/Carthage/Build/iOS/Result.framework
$(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
This script works around an App Store submission bug triggered by
universal binaries and ensures that necessary bitcode-related files
and dSYMs are copied when archiving.
However, I can't find the Build Phases tab anymore or Run Script in the Build Settings search. The Xcode 8 Release Notes mention
Xcode 8 provides completely rewritten AppleScript support. A new
scripting dictionary provides the ability to automate Xcode workflows.
Does that mean there is no more Run Script? I looked at AppleScript but honestly it looks overwhelmingly complex. Do I need to learn AppleScript just to add the simple one liner that I used to do in Xcode?
/usr/local/bin/carthage copy-frameworks
It is still there. Make sure you click everywhere indicated in red in the image below.
Carthage maintainers updated README, it is necessary to add output paths too to prevent useful copying of frameworks. I have released simple script named Carting to automate these steps.

How do I use SwiftyJSON in my iOS App?

I recently added SwiftyJSON into my xCode project using Carthage.
Cartfile
$ cat Cartfile
github "SwiftyJSON/SwiftyJSON" >= 2.1.2
I ran this command to install SwiftyJSON
$ carthage update
I added the built Framework to my xCode project
I imported the Framework at the top of my project
But I still get this error:
Use of unresolved identifier 'JSON'
Seriously, what am I doing wrong? I'm new to iOS development.
UPDATE: I tried removing the Frameworks and re-dragging the frameworks to the Linked Frameworks and Libraries and Adding the "Run Script" section to "Build Phases" as the instructions in Carthage asked.
I'm convinced that something went awry during the Carthage Update process because I received this error on my initial attempt:
$ carthage update
*** Fetching SwiftyJSON
*** Fetching Alamofire
*** Checking out SwiftyJSON at "2.1.3"
*** Checking out Alamofire at "1.1.4"
*** xcodebuild output can be found in /var/folders/0x/swzt630n3_575tglljpwhn4h0000gn/T/carthage-xcodebuild.Pc6rLg.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire OSX" in Alamofire.xcworkspace
*** Building scheme "SwiftyJSON" in SwiftyJSON.xcworkspace
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
After looking up the problem, I was told that you could run
carthage update --configuration Debug
Which installed it fine, but something is still amiss...
It seems like you missed a step during the addition of SwiftyJSON and Alamofire frameworks from Carthage. Check out these steps from the Carthage readme page :
Steps :
Create a Cartfile that lists the frameworks you’d like to use in your project.
Run carthage update. This will fetch dependencies into a Carthage/Checkouts folder, then build each one.
On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.
On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following contents:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
$(SRCROOT)/Carthage/Build/iOS/SwiftyJSON.framework
Looks like you missed step 4. I tried these steps myself in a demo Swift project and they are working great. Try these steps out, and if you still have problems, leave a comment. Thanks!
I switched over to Cocoapods and it just worked. Again, I'm a total noob when it comes to iOS development. When looking for a dependency manger I looked at Cocoapods and Carthage for what they had to offer. I was intrigued by Carthage's claim of keeping things simple:
"Carthage because we wanted the simplest tool possible—a dependency manager that gets the job done without taking over the responsibility of Xcode"
While I always will choose the simpler tool when given a choice, I think I don't know enough of the iOS ecosystem (read: Xcode) to use Carthage.
TL,DR: Can't use it inside of Emulator, Use iPhone.
I also followed your way, and I found out that --configuration debug will code-sign "iOS Developer" identity as SwiftyJSON's project property.
AFAIK, Code-signed "iOS Developer" identity wasn't run with Emulator.
My issue was resolved when I run it at my iPhone 6.
I do not know why you can not add this resource with help of Carthage but if you need use SwiftyJSON you only need:
Enter this URL: SwiftyJSON
Clic the button "Clone or download" and then in "Download ZIP" like the next image shows:
Clic the button "Clone or download" and then in "Download ZIP" IMG
You will get a ZIP file with name "SwiftyJSON-master"
Extract the files
Enter the path:
SwiftyJSON-master/Source/
You will see a file with name:
SwiftyJSON.swift
Copy that file into the files of your project.
Add that file into your project directory.
That file will be like other class into your project that you may use.

Resources