Why should you use CocoaPods?

This blog post has the intention to show to beginners the tool called CocoaPods, if you’re already familiar with it you may find it boring because I’ll probably show you something you already now.

What’s CocoaPods?

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

If you’re familiar with Rails, you may remember the Gemfile system, and yes, it works just like that. In fact CocoaPods is a gem for Ruby. You can contribute for the project by sending a pull request on the official repository.

 

The advantages of using CocoaPods

You are ready to develop your first iOS project, you’re full of ideias, at first having a dependency manager seems to be pretty not necessary, but remember, you app won’t be the same after every update, in fact, if you’re planning to build the next successful app, you may need starting worrying about how to organize it, this where CocoaPods comes in.

Managing a project dependencies by hand it is not the best ideia, actually, it is a terrible idea, imagine having a project with 50 dependencies and having to update all of them ? Scary huh ? That’s the reason you need a project manager, with CocoaPods if you want to update a pod(That’s how a dependency is called in CocoaPods, like a gem in Ruby) you just need to type:

pod update the_name_of_the_pod

and it will do all the work for you, after that you just need to recompile your project on XCode, and that’s all.

Another reason to use CocoaPods is: a lot of big companies are using it, like Facebook , Google and many others.

You have a lot of support, there are thousands of apps using it, and Stackoverflow if full of questions about it.

Acknowledgment

Thanks for reading this post, it is always a pleasure writing for you guys. If you like what you just read and somehow you want to support me, you can become a Patreon . Being my Patreon makes you get my private posts about programming with iOS and Ruby.

If you’d like to know more about me or what I do, you can follow me on Instagram or Twitter .

See you next time!

Advertisements

How to solve: Sorry, you can’t use byebug without Readline (Mac OS)

Byebug is a nice gem for debugging Ruby 2.

The most common problem to happen using this gem is the error: ‘Sorry, you can’t use byebug without Readline‘ , lucky for those running Mac OS, this issue can be simply solved by using this command on terminal:

ln -s /usr/local/opt/readline/lib/libreadline.dylib /usr/local/opt/readline/lib/libreadline.6.dylib

How to get the full path image url with carrierwave gem

In this post I’m going to cover how to get the full path url of an uploaded image using carrierwave gem.

By default carrierwave stores the uploaded images at /uploads/model_name/id/image.png

If you request the image url from the database it will only return the /uploads/model_name/id/image.jpg directory.

What if you need the full path ? Like: http://www.mysite.com/uploads/model_name/id/image.jpg

The only thing you need to do is to to set the asset_host in your development/production environment:Captura de Tela 2016-06-05 às 07.56.20.png

After that you need to restart your server and now you can get the full path of the image.

Feel free to ask questions and make suggestions 🙂

Acknowledgment

Thanks for reading this post, it is always a pleasure writing for you guys. If you like what you just read and somehow you want to support me, you can become a Patreon . Being my Patreon makes you get my private posts about programming with iOS and Ruby.

If you’d like to know more about me or what I do, you can follow me on Instagram or Twitter .

See you next time!

Cpf_Validation Gem

Some days ago I released my first gem for CPF validation.

I’ve seen many gems which do the same but the authors seem to no update them.

You can help me to improve this gem by sending a pull request on github: https://github.com/GabrielLidenor/cpf_validation

Installation

As gem:

# in Gemfile
gem 'cpf_validation'

# Run bundler
$ bundle install

Usage

Validating a CPF attribute:

class Patient < ActiveRecord::Base
  validates_cpf :cpf_attr
  # or
  validates :cpf_attr, :cpf => true
end

Validating an attribute that can store CPF:

class Customer < ActiveRecord::Base
  validates_cpf :cpf_attr
  # or
  validates :cpf_attr, :cpf => true
end

Regular validation options:

:allow_nil   - Allows a nil value to be valid
:allow_blank - Allows a nil or empty string value to be valid
:if          - Executes validation when :if evaluates true
:unless      - Executes validation when :unless evaluates false
:on          - Specifies validation context (e.g :save, :create or :update). Default is :save