Project Source Address: Https://github.com/Carthage/Carthage
Think of Ios/os X project's dependency management, the first thought must be the famous cocoapods. Here is a description of the difference between the two Carthage:
CocoaPods (default) automatically establishes and updates a Xcode workspace, which is used to manage your projects and all dependencies. Carthage uses Xcodebuild to compile the binary library, and the rest of the integration work is left entirely to the developer.
The cocoapods is easy to use, Carthage more flexible and does not have much aggressiveness for existing projects.
Cocoapods wants to build an ecosystem that makes it easier to discover and integrate third-party code repositories. Carthage wants to become a centralized dependency management system that does not provide a centralized list of projects, reducing maintenance costs and the probability of a single point of failure. However, it is inconvenient for developers to find projects.
The Cocoapods project requires configuration of the Podspec file, which contains information about the project and the third-party library. Carthage does not use a similar configuration file, the dependencies of third-party libraries are configured through the Xcode project.
Installing Carthage
1. Download the installation package directly: address, but the file host on Amazon S3, I tried several times did not ...
2. Using homebrew
Install Carthage
Compiling third-party libraries
1. Create Cartfile to list the third-party library information you want to use, here's a simple example
Constructs two libraries: Reactivecoca 2.3.1 version and above, Mantle 1.x version
2.3. 1 "reactivecocoa/reactivecocoa"2.3. 1 1"mantle/mantle"1.0 # (1.0 less2.0)
2. Run Carthage Update
Carthage Update
3. This will generate the following file directory
|-Carthage|---Build|-----Mac|-------mantle.framework|---------Versions|-----------A|-------------Headers|-------------Modules|-------------Resources|-------reactivecocoa.framework|---------Versions|-----------A|-------------Headers|-------------Modules|---------------Reactivecocoa.swiftmodule|-------------Resources|-----IOS|-------mantle.framework|---------Headers|---------Modules|---------_codesignature|-------reactivecocoa.framework|---------Headers|---------Modules|-----------Reactivecocoa.swiftmodule|---------_codesignature|---Checkouts|-----LIBEXTOBJC|-------Configuration|---------Base|-----------configurations|-----------Targets|---------Mac OS X|---------IOS|-------Tests|-------EXTOBJC|-------extobjc.xcodeproj|---------Project.xcworkspace|---------Xcshareddata|-----------Xcschemes|-----Xcconfigs|-------Base|---------configurations|---------Targets|-------Mac OS X|-------IOS
Carthage/checkouts Directory: Source code obtained from GitHub
Carthage/build directory: Compiled framework binary code library
4. Open the project, and drag and drop the framework library you want to import in the Carthage/build directory, in the Link library with Libraries, Build phases, which is a project target.
5. Add additional compiled scripts and click on "+"-New Run script Phase
Add a script
/usr/local/bin/carthage Copy-frameworks
Add "Input Files"
$ (srcroot)/carthage/build/ios/mantle.framework$ (srcroot)/carthage/build/ios/reactivecocoa.framework
6. Use of third-party libraries in projects
#import "AppDelegate.h"#import<ReactiveCocoa/ReactiveCocoa.h>#import<Mantle/Mantle.h>@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Override point for customization after application launch.Nsarray*array = @[@"a",@"b"]; NSLog (@"%@", [array mtl_firstobject]); returnYES;}
7. Run the project to view the output
--------£ º56.858 carthageproject[3733: 227021] A
Done!
Carthage uses a very streamlined approach to managing third-party libraries, compiling the source code into the framework's binaries, and then letting developers take care of the library's management, import, and so on. It is easier to use than cocoapods, which reduces the intrusion of existing projects.
Carthage-A simple, centralized cocoa dependency manager