Top 5 iOS Libraries Every iOS Developer Should Know About

top-5-ios-libraries-every-ios-developer-should-know-about-0

You probably know that using third-party libraries in your iOS projects can save you a lot of time and hassle. The question is, which libraries are worth using? Read on and find out!

Note: Looking for Swift libraries? Head over to Top 10 iOS Swift libraries every iOS developer should know about

Services like GitHub or Bitbucket are full of useful third-party libraries that can be easily integrated into your project by using tools like CocoaPods and Carthage. Here are 5 libraries that we use in every-day development and think every iOS developer should know about.

title

When it comes to networking, this library makes every developer’s life a whole lot easier. AFNetworking is a light-weight and fast networking library that uses blocks and GCD (Grand Central Dispatch).

It is a great example of how an open-source project should be run, largely thanks to its creator Mattt Thompson, the founder and former writer on NSHipster. An amazing community of developers contributes to AFNetworking daily, making it the most popular third-party iOS library.

To see just how easy it is to use it, check out the code example below:

GET request

	AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

POST request

	AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

Swift alternative

Alamofire – also made by Mattt

If you are working on an app that requires communication with a remote server, chances are you’ll get a JSON response. This is where JSONModel comes to the rescue.

JSONModel is an open-source library that helps you with parsing and initializing your model classes with JSON response from the server. When it comes to applications with a more complex data model, JSONModel proves to be a real time-saver.

Initializing model from JSON response

	JSONModelError *jsonModelError = nil;
PersonModel *personModel = [[PersonModel alloc] initWithDictionary:personDictionary error:&jsonModelError];

Swift alternative

ObjectMapper – this framework written in Swift simplifies the conversion of Model objects (Classes and Structs) to JSON and vice versa

The Core Data API is used by iOS developers to persist and query user data. While powerful, using its API can also be quite time-consuming and contain a lot of boilerplate code.

Luckily, you can help yourself by using a library called MagicalRecord, a wrapper around Core Data that simplifies managing your persistence storage. It was inspired by the ease of Ruby on Rails’ Active Record fetching and it allows you to:

  • Clean up your Core Data related code
  • Use simple, one-line fetches
  • Modify the NSFetchRequest when request optimizations are needed

Let’s see how we can put MagicalRecord to use:

Create an object

	Person *person = [Person MR_createEntity];
person.name = @“Vedran”;
person.age = @23;

Retrieve all records for the NSManagedObject subclasses

	NSArray *people = [Person MR_findAll];

Updating an entity

	person.age = @28;

Delete single record

	[person MR_deleteEntity];

Swift alternative

SugarRecord – a data management library designed to make working with CoreData and Realm simpler

AFNetworking has a great category to load images from the web (UIImageView+AFNetworking), but there’s a library even more suited to this task.

SDWebImage specializes in image downloading and caching, and offers an extensive list of features:

  • A UIImageView category adding web image and cache management to the Cocoa Touch framework
  • An asynchronous image downloader
  • An asynchronous memory + disk image caching with automatic cache expiration handling
  • Animated GIF support
  • Background image decompression
  • Guarantees that the same URL won’t be downloaded several times
  • Guarantees that bogus URLs won’t be retried again and again
  • Guarantees that the main thread will never be blocked

Here is a basic example of usage:

Load remote image using blocks

	[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
                placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                       completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {… completion code here …}];

Swift alternative

Kingfisher – lightweight and pure Swift implemented library for downloading and caching images from the web

Objective-C framework inspired by functional programming. It provides methods to compose and transform streams of values. It functions by using signals (RACSignal) that capture present and future values. You can observe and update values by chaining, combining and reacting to signals.

A major advantage of ReactiveCocoa is that it provides a way to deal with asynchronous behaviors, including delegate methods, callback blocks, target-action mechanisms, notifications and KVO, simply by using signals.

Basic usage

Check if the email length is greater than 0, password length greater than 8, and enable the login button if both requirements are met.

	RACSignal *formValid = [RACSignal
                            combineLatest:@[
                                            self.emailField.rac_textSignal,
                                            self.passwordField.rac_textSignal
                                            ]
                            reduce:^(NSString *email, NSString *password) {
                                return @([email length] > 0 && [password length] > 8);
                            }];

    RAC(self.loginButton.enabled) = formValid;

ReactiveCocoa has grown to be quite a big piece of library, and I recommend that you check its GitHub page to see everything it can do.

Swift alternative

ReactiveCocoa v3.0 will contain a brand new Swift API. You can learn more in this great blog post written by Scott Logic.

Honorable mentions

  • SVProgressHUD – Clean and easy-to-use HUD intended for displaying the progress of an ongoing task
  • BlocksKit – Objective-C framework which facilitates the use of blocks for many iOS native classes such as UIAlertView, UIWebView, UIActionSheet, NSArray, etc.
  • pop – An extensible animation engine for iOS and OS X
  • FormatterKit – Collection of well-crafted NSFormatter subclasses for things like units of information, distance and relative time intervals
  • Masonry – Light-weight layout framework which wraps AutoLayout with a nicer syntax
  • XLForm – The most flexible and powerful iOS library to create dynamic table-view forms
  • IDAlertController – iOS7-safe UIAlertController
  • FBAnnotationClustering – An iOS library for fast and easy clustering of map notifications (here’s a nice blog post about it)