336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
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!

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.


1. AFNetworking

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);
}];


2. JSONModel

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];


3. MagicalRecord

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];


4. SDWebImage

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 ...}];


5. ReactiveCocoa

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.


posted by 어린왕자악꿍