Cocoa Touch Static Library: CoreData
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 80 commits behind acani:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Cocoa Plant

Merriam-Webster defines plant as:

1 a : a young tree, vine, shrub, or herb planted or suitable for planting

and the verb to plant as:

1 a : to put or set in the ground for growth

Chief Definite Aim

In that vein, the aim of Cocoa Plant is to grow the Cocoa frameworks & libraries by adding useful classes, categories, and methods to make Cocoa even better.


Currently, Cocoa Plant is a Cocoa Touch Static Library for use with iOS apps.

Cocoa Plant consists of three parts:

  1. Plantation (Foundation)
  2. UIPlant (UIKit)
  3. PlantData (CoreData)


NSString leading & trailing trimming methods, words method.

[[[NSFileManager alloc] init] URLForApplicationDirectory:NSDocumentDirectory]


UIAlertView: showWithTitle:, showWithError:


Set up the Core Data stack with one method call:

[NSManagedObjectContext contextWithStoreType:NSSQLiteStoreType error:&error]

Customize fetch requests with blocks:

NSArray *results = [User fetchInContext:context error:&error
                                options:^(NSFetchRequest *request) {
                                    [request setFetchLimit:1];
                                    [request setPredicate:predicate];
                                    [request setSortDescriptors:sortDescriptors];
                                    // ...

Project Setup

Add Cocoa Plant as a Git submodule to the Libraries directory.

This will help you pull in updates and make contributions.

cd ~/Projects/Acani/ # sample project root directory

# Let's make a new directory called Libraries for third-party code.
git submodule add Libraries/CocoaPlant
git submodule update --init
git commit -am 'Add CocoaPlant as a submodule.'

Add Cocoa Plant to Your Xcode Project.

Add the Libraries group to your Project.

In Xcode, select your project at the top of the Project Navigator (⌘1), and press ⌥⌘N to create a new group. Name it, e.g., "Libraries." Then, select the Libraries group, press ⌥⌘0 to Show Utilities, click the small icon to the right just below Path, choose the Libraries directory. Drag the Libraries group to move it before the Frameworks group.

Add CocoaPlant.xcodeproj inside the Libraries group.

With the Libraries group selected, press ⌥⌘A to add files, select CocoaPlant.xcodeproj in Libraries/CocoaPlant, and confirm that "Copy items into destination group's folder (if needed)" is unchecked, "Create groups for any added folders" is selected, and all targets are unchecked. Then, click Add.

In Terminal, review and commit your changes:

git diff -w -M --color-words HEAD
git commit -am 'Add Libraries group. Put CocoaPlant.xcodeproj inside.'

Edit Your Application Project Settings.

In Xcode, select your main Xcode project at the top of the Project Navigator (⌘1), and then, select the project (or target) to which you want to add Cocoa Plant. (To allow all your targets, e.g., your tests target (along with your application target), to import Cocoa Plant, apply these settings at the project level.)

Edit Build Phases.

Select the "Build Phases" tab.

  • Under the "Target Dependencies" group, click the plus button, select CocoaPlant from the menu, and click Add.
  • Under the "Link Binary With Libraries" group, click the plus button, select libCocoaPlant.a from the menu, and click Add.

Edit Build Settings.

Select the "Build Settings" tab. Make sure "All" is selected in the top left of the bar under the tabs.

In Terminal, review and commit your changes:

git diff -w -M --color-words HEAD
git commit -am 'Edit target info, phases & settings for Cocoa Plant.'

Using Cocoa Plant in Your App

  • Include Cocoa Plant in any files that use it:

      #import <CocoaPlant/CocoaPlant.h>
  • To reduce build times, create a precompiled header file. E.g., AppName-Prefix.pch:

      #include "AppName-Prefix.pch"
      #ifdef __OBJC__
      // Frameworks
      #import <Foundation/Foundation.h>
      // Libraries
      #import <CocoaPlant/CocoaPlant.h>

    Specify the path to this precompiled header in your test target's Build Settings under Prefix Header.

  • Include Cocoa Plant in your app's prefix header file, e.g., AppName-Prefix.pch:

      #import <CocoaPlant/CocoaPlant.h>

Updating the Cocoa Plant iOS SDK

Pull in remote updates by running these commands from your project root directory:

git submodule foreach 'git checkout master; git pull --rebase'
git commit -am 'Update submodules to latest commit.'

You can add an alias (to ~/.gitconfig) for the first of the two commands above:

git config --global alias.sup "submodule foreach 'git checkout master; git pull --rebase'"

Then, to pull in remote updates, you can just do:

git sup

Contributing to the Cocoa Plant iOS SDK

  • Commit your changes.

      cd ~/Projects/Acani/Libraries/CocoaPlant
      git add -A
      git commit
  • Fork this repo on GitHub, add your fork as a remote, and push.

      git remote add myusername
      git push myusername master
  • Send Cocoa Plant a pull request on GitHub.