Home

Awesome

CocoaSeeds

Gem Build Status

Git Submodule Alternative for Cocoa. Inspired by CocoaPods.

Why?

Installation

You can get CocoaSeeds from RubyGems.

$ [sudo] gem install cocoaseeds

How to Use CocoaSeeds

1. Write a Seedfile

A Seedfile is a ruby script that manifests the dependencies of your project. You can manage third party libraries by simply specifying them in the Seedfile. Currently, CocoaSeeds supports only GitHub and BitBucket repositories. However, we are planning to support other version control systems.

Let's make an empty file named Seedfile in the directory where your Xcode project file is located. Here is a sample Seedfile:

Seedfile

github "Alamofire/Alamofire", "1.2.1", :files => "Source/*.{swift,h}"
github "devxoul/JLToast", "1.2.5", :files => "JLToast/*.{swift,h}"
github "devxoul/SwipeBack", "1.0.4"
github "SnapKit/SnapKit", :commit => "62e7645", :files => "Source/*.{swift,h}"

git "https://gitlab.com/MyCompany/CompanyLibrary.git", "1.1.0"
local "PrivateLibrary", "../libs/PrivateLibrary", :files => "Source/*.{swift,h}"

target :MyAppTest do
  github "Quick/Quick", "v0.3.1", :files => "Quick/**.{swift,h}"
  github "Quick/Nimble", "v0.4.2", :files => "Nimble/**.{swift,h}"
end

Can you guess what each line does? It has basic information about the third party libraries.

Each line in a Seedfile consists of three parts: source, tag, and files. Let's look at the second line of the previous sample.

github "devxoul/JLToast", "1.2.5", :files => "JLToast/*.{swift,h}"
~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       (Source)          (Version)             (Files)
PartsExampleRequiredDefault
Sourcegithub "devxoul/SwipeBack"Required-
VersionTag: "1.0.4"<br>Branch: "swift-2.0"<br>Commit: :commit => "SHA1"Required-
Files:files => "JLToast/*.{swift,h}"Optional*/**.{h,m,mm,swift}

Tip: You can pass an array to :files for multiple file patterns:

:files => ["/path1/*.swift", "/path2/*.swift"]

Want to use branch names instead of tags? See the Branch support section.

Specifying targets

Third party libraries can be included as a specific target by creating a target block. For example, if you want to add some testing libraries such as Quick and Nimble into test target, you can specify them like this:

target :MyAppTest do
  github "Quick/Quick", "v0.3.1", :files => "Quick/**.{swift,h}"
  github "Quick/Nimble", "v0.4.2", :files => "Nimble/**.{swift,h}"
end

Specifying Xcode project file path

If the .xcodeproj file is located in other location, you can specify the path in Seedfile.

xcodeproj "path/to/Project.xcodeproj"

target :MyApp do
    github "devxoul/JLToast", "1.2.5", :files => "JLToast/*.{swift,h}"
end

2. Install dependencies

After you are done with your Seedfile, it's time to load those libraries into your project. This is pretty simple. Just open the terminal, cd to your project directory and execute seed install command.

$ seed install

Then, all the source files will be automatically downloaded and added to a group named 'Seeds'.

Seeds-in-Xcode

3. Enjoy

Build your project and enjoy coding!

Tips and Tricks

Using branches

You can specify a branch name instead of the tag. What you need to do is just replacing the tag with the branch name.

github 'devxoul/SwiftyImage', 'swift-2.0', :files => 'SwiftyImage/SwiftyImage.swift'

Excluding files

Use exclude_files to exclude files from files pattern.

github 'devxoul/Carte', '0.2.2', :files => 'Carte/*', :exclude_files => "Carte/Carte.h"

Using resources

If the resource files are sprecified in files, they will be added to Copy Bundle Resource build phase instead of Compile Source build phase.

github 'author/Repository', 'x.y.z', :files => ['Source/*', 'Images/*']

Resolving filename conflicts

Since CocoaSeeds tries to include source files directly rather than linking dynamic frameworks, it is important to make sure that all sources have different names. CocoaSeeds provides a way to do this:

Seedfile

<pre> <b>swift_seedname_prefix!</b> # add this line github "thoughtbot/Argo", "v1.0.3", :files => "Argo/*/*.swift" github "thoughtbot/Runes", "v2.0.0", :files => "Source/*.swift" </pre>

Then all of source files installed via CocoasSeeds will have names with the seed names as prefix.

Before (filename)After (seedname_filename)
Seeds/Alamofire/Alamofire.swiftSeeds/Alamofire/Alamofire_Alamofire.swift
Seeds/Argo/Operators/Operators.swiftSeeds/Argo/Operators/Argo_Operators.swift
Seeds/Runes/Operators.swiftSeeds/Runes/Runes_Operators.swift

FAQ

License

CocoaSeeds is under MIT license. See the LICENSE file for more info.