Useful iOS Libraries

Useful iOS Libraries

Here are sites declaring and discussing useful iOS Libraries:

  1. http://www.raywenderlich.com/21987/top-10-most-useful-ios-libraries-to-know-and-love
  2. http://www.devx.com/opensource/ten-fantastic-objective-c-libraries-for-iphone-developers.html
  1. FMDB
    1. Open Source available at github 
    2. a wrapper on top of the base API (iOS SDK provides API but in pure C language for DB operations) and provides easy to use methods to perform database operations using Objective-C language.
    3. Can be installed via cocoapods
      1. Need to install cocoa pods first. Read my post of installing cocoapods.
      2. Search FMDB on cocoapods‘ site and copy the information
        pod ‘FMDB’, ‘~> 2.3’
      3. $ cd to the xcode project’s folder
      4. $ pod init
      5. $ vi Podfile
        1. press a or i to insert
        2. pod ‘FMDB’, ‘~> 2.3’
        3. esc :wq return
      6. $ pod install
        Analyzing dependencies
        Downloading dependencies
        Installing FMDB (2.3)
        Generating Pods project
        Integrating client project[!] From now on use `App.xcworkspace`.
      7. $ open -a Xcode App.xcworkspace
    4. Tutorial: Simple Sqlite database handling
      1. Installation
        Here installation is done manually but I would prefer the automated one as discussed above
      2. Creating Database
        #import "FMDatabase.h"
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *docsPath = [paths objectAtIndex:0];
        NSString *path = [docsPath stringByAppendingPathComponent:@"database.sqlite"];
         
        FMDatabase *database = [FMDatabase databaseWithPath:path];

        NSCachesDirectory would be used if you don’t want the database file to be backed up to iCloud and iTunes. And to avoid being backed up with NSDocumentDirectory use this solution.

      3. Create Tables
        [database open];
        [database executeUpdate:@"create table user(name text primary key, age int)"];

        Make sure it is executeUpdate and not executeQuery, a common error.

      4. Insertion
        // Building the string ourself
        NSString *query = [NSString stringWithFormat:@"insert into user values ('%@', %d)",
        @"brandontreb", 25];
        [database executeUpdate:query];
         
        // Let fmdb do the work: This is preferred as fmdb will do some of the sanitizing for your (such as add slashes to single quotes)
        [database executeUpdate:@"insert into user(name, age) values(?,?)",
        @"cruffenach",[NSNumber numberWithInt:25],nil];
      5. Querying// fetching all users from the database
        FMResultSet *results = [database executeQuery:@"select * from user"];
        while([results next]) {
            NSString *name = [results stringForColumn:@"name"];
            NSInteger age  = [results intForColumn:@"age"];        
            NSLog(@"User: %@ - %d",name, age);
        }
        [database close];
        
        // FMDB has some great utility methods for helping us out in certain circumstances. This tutorial doesn't discuss those. So, I need to find out those as well.
      6. Deletion
        [database executeUpdate:@"delete from user where age = 25"];
  2. BRORM
    Use this library to further simplify the FMDB

      1. installation
        1. via github
        2. via cocoapods as discussed above
      2. Source Code
        1. Read readMe file to learn how to use BRORM
        2. Github Example Code
  3. ZSSRichTextEditor
    1. Installation
      1. via github
      2. via cocoapods as discussed above
    2. Usage
      1. Just subclass ZSSRichTextEditor
        #import “ZSSRichTextEditor.h”
        MyVC : ZSSRichTextEditor
  4. iOS-Rich-Text-Editor

    1. Installation
      1. via github
      2. via cocoapods as discussed above
  5. ASIHTTPRequest
    1. Installation
      1. via github
      2. via cocoapods as discussed above

Troubleshooting:
CocoaPods install command may take some time to get installed but if it seems stuck and doesn’t seem working then it may need to be fixed as follows:

Scenario 1:
$ pod install
Analyzing dependencies
… seems stuck

Scenario 2:
$ pod install
Analyzing dependencies
… No such file or directory – /.cocoapods/repos (Errno::ENOENT) …

Fix:
This solution at stackoverflow seems working

  1. $ pod repo remove master
    Removing spec repo `master`
  2. $ pod setup
    Setting up CocoaPods master repo (It took a while to complete)
    Setup completed (read-only access)
  3. $ pod install
    Analyzing dependencies
    Downloading dependencies
    Installing SOME-LIBRARY
    Generating Pods project
    Integrating client project
Advertisements

One thought on “Useful iOS Libraries

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s