Cocoa pods in xamarin iox

Hope you know what is Cocoa pods?

cocoa pods is …

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 37 thousand libraries and is used in over 2.6 million apps. CocoaPods can help you scale your projects elegantly.

First of all you need install ruby and cocoapods gem in to your mac.

Better if you have latest ruby version . You can check your ruby version using following code when you run on your terminal (mar terminal)

1
ruby -v

If you want to update ruby , better to use multiple ruby version with same machine. To do that I am recommend to use

rvm – Ruby Version Manager

Todo it you need to install Homebrew. For it first you need to run following command in terminal,

1
xcode-select --install

Your computer will then attempt to find the software, and then will start downloading it. A popup will appear.

Once the software is installed, click Done. That’s it! You’re now ready to install homebrew .

1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To install rvm use following code on terminal

1
curl -L https://get.rvm.io | bash -s stable --auto-dotfiles --autolibs=enable --rails

This will take a few minutes, and once it’s done, quit and relaunch Terminal, then run this command:

1
type rvm | head -1

If you get rvm is a function, that means RVM was successfully installed. If not, go to the Troubleshooting section.

To make sure the latest versions of RVM, Ruby and Rails were installed, run the commands below:

For RVM

1
rvm -v

You should get rvm 1.29.1 or higher.

Now you can install new ruby version using following code.

1
rvm install [version]

eg :

1
rvm install 2.3.1

This output also lets you know which version is the default and which one is the current one in use.

To use a specific version (2.2.0 in the example below) and also set it as the default version for new shell sessions:

1
rvm use 2.3.1 --default

Wow now you are ready to install cocoapods. To install cocoapods you following code on your mac terminal

1
sudo gem install cocoapods

Now all done. Now we want to use cocoapods libraries with xamarin. Todo that we need to install another package to your mac. its call

1
Sharpie

Sharpie

Objective Sharpie is currently a standalone command line tool for Mac OS X 10.10 and newer, and is not a fully supported Xamarin product. It should only be used by advanced developers to assist in creating a binding project to a 3rd party Objective-C library.

Objective Sharpie can be downloaded as a standard OS X package installer. Run the installer and follow all of the on-screen prompts from the installation wizard:

Current Version: 3.3
Download Latest Release
Forum Announcement
Tip: use the sharpie update command to update to the latest version.

The sharpie pod command has one global option and two subcommands:

1
2
3
4
5
6
7
8
9
10
$ sharpie pod -help
usage: sharpie pod [OPTIONS] COMMAND [COMMAND_OPTIONS]

Pod Options:
  -d, -dir DIR     Use DIR as the CocoaPods binding directory,
                   defaulting to the current directory

Available Commands:
  init         Initialize a new Xamarin C# CocoaPods binding project
  bind         Bind an existing Xamarin C# CocoaPods project

The init subcommand also has some useful help:

1
2
3
4
5
6
$ sharpie pod init -help
usage: sharpie pod init [INIT_OPTIONS] TARGET_SDK POD_SPEC_NAMES

Init Options:
  -f, -force       Initialize a new Podfile and run actions against
                   it even if one already exists

Multiple CocoaPod names and subspec names can be provided to init.

1
$ sharpie pod init ios SWNetworking

I used SWNetworking library for example.

after above code you will see success message on the terminal.

Screen Shot 2017-09-25 at 4.49.50 PM

Once your CocoaPod has been set up, you can now create the binding:

1
$ sharpie pod bind

This will result in the CocoaPod Xcode project being built and then evaluated and parsed by Objective Sharpie. A lot of console output will be generated, but should result in the binding definition at the end:

Screen Shot 2017-09-25 at 5.15.26 PM

That is it. You are done… :)

Write a Reply or Comment

Your email address will not be published.