Getting Started With VendorKit

| Comments

Hi! this is the first post of  2012, more posts will be coming during the rest of the year, at least more than the last year, that was really a shame by the way. So le’t do this!

What is VendorKit?

Overview

VendorKit makes the process of using and managing libraries in iOS easy. VendorKit is modeled after Bundler. VendorKit streamlines the installation and update process for dependent libraries. It also tracks versions and manages dependencies between libraries.

How does it work?

VendorKit works by making direct modifications to your project file. When you install a library, vendor will copy all the source files, build setting and frameworks to your project, then save it. That way, when you want to install a library, all you have to do is add it to your Vendorfile, and then type into your Terminal vendor install

Installation

If you have RVM installed, simply run:

$ gem install vendor

Otherwise, you’ll need to:

$ sudo gem install vendor

Using VendorKit

in this example i’m gonna create a new project and then use the AFNetworking networking framework to load an Image, this dependency will be loaded using a Vendorfile, so first create a new single view application and call it VendorKitTest.

Installing Libraries

open terminal go to your working project directory and then run the following

$ vendor init

open the recently created Vendorfile and repleace it with the contents of this:

# Checks out the git repo and includes all the files found in the
# AFNetworking folder in the repo. The require option is handy for
# repo's that haven't created vendor libraries and pushed them to
# VendorKit
lib "DKRest", :git => "git://github.com/gowalla/AFNetworking.git", :require => "AFNetworking"

Installing dependencies

in terminal run

$ vendor install
$ git add Vendors.lock

Installing a vendor library gets the latest version of the code, and adds them directly to your project in a Vendor group.

As part of the installation process the required frameworks are added aswell as any compiler/linker flags. The installed version of the library is captured in the Vendors.lock file.

you project should look like this:

Using AFNetworking

now that you have installed AFNetworking library, let’s use it! open the ViewController.m implementation file and add the next code:

//
//  ViewController.m
//  VendorKitTest
//
//  Created by Raul Uranga on 1/6/12.
//  Copyright (c) 2012 GrupoW. All rights reserved.
//

#import "ViewController.h"
#import "UIImageView+AFNetworking.h"

@implementation ViewController

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480)];
    [imageView setImageWithURL:[NSURL URLWithString:@"http://pastorbrennan.com/wp-content/uploads/2011/11/1.jpg"]];
    [self.view addSubview:imageView];
    [imageView release];
}

and that’s it, you should see a nice retro apple logo like this:

as you can see using vendorkit can save you lots of time for installing dependecies, and it’s really easy to use for more information about creating libraries you can go here you can download the example project from here.

happy coding.

Comments