<> Restkit is used in IOS projects, including xcode configuration instructions.

Source: Internet
Author: User

Recently, restkit has been added to the iPhone project and compiled. However, due to the fact that many unreliable instructions have been found before, the compilation fails for one day and an inexplicable error is always reported. Finally, I found a more authoritative English document at the last moment to find that my problem lies in a very detailed place. The conclusion is that unreliable documents have killed people.

The following describes how to use restkit in the xcode project.

1. Download The restkit source code, go to the official website, download and unzip the source code without too much explanation;

2. Create an iOS project in xcode and copy the restkit source code in the project folder.

3. Drag the restkit. xcodeproj file in restkit to the resource manager of xcode.

4. Select the top-level project, select the project in the middle column, and set

(1) locate the header search path in build setting and set it to "$ (source_root)/restkit/build"

(2) Find the library search path in build setting and set it to "$ (source_root)/restkit/build/$ (build_style)-$ (platform_name )"

5. Select an item in the middle column of target, click the build phase tab, and add restkit to target dependence.

6. Add the following package name to link binary with libraries:

Librestkitcoredata.

Librestkitjsonparseryajl.

Librestkitnetwork.

Librestkitobjectmapping.

Librestkitsupport.

Cfnetwork. Framework

Coredata. Framework

Mobilecoreservices. Framework

Systemconfiguration. Framework

7. Introduce in the header file

# Import <restkit/restkit. h>

# Import <restkit/coredata. h>

Click compile. If no problem occurs, the compilation is successful.

 

Now let's perform a simple test:

Add the following code to the applicationdidfinishlaunching function:

- (void)applicationDidFinishLaunching:(UIApplication*)application withOptions:(NSDictionary*)options {  
    RKClient* client = [RKClient clientWithBaseURL:@"http://restkit.org"];  
}

The test is as follows:

#import <RestKit/RestKit.h>  

// Here we declare that we implement the RKRequestDelegate protocol
// Check out RestKit/Network/RKRequest.h for additional delegate methods
// that are available.
@interface RKRequestExamples : NSObject <RKRequestDelegate> {
}

@end

@implementation RKRequestExamples

- (void)sendRequests {
// Perform a simple HTTP GET and call me back with the results
[[RKClient sharedClient] get:@"/foo.xml" delegate:self];

// Send a POST to a remote resource. The dictionary will be transparently
// converted into a URL encoded representation and sent along as the request body
NSDictionary* params = [NSDictionary dictionaryWithObject:@"RestKit" forKey:@"Sender"];
[[RKClient sharedClient] post:@"/other.json" params:params delegate:self];

// DELETE a remote resource from the server
[[RKClient client] delete:@"/missing_resource.txt" delegate:self];
}

- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
if ([request isGET]) {
// Handling GET /foo.xml

if ([response isOK]) {
// Success! Let's take a look at the data
NSLog(@"Retrieved XML: %@", [response bodyAsString]);
}

} else if ([request isPOST]) {

// Handling POST /other.json
if ([response isJSON]) {
NSLog(@"Got a JSON response back from our POST!");
}

} else if ([request isDELETE]) {

// Handling DELETE /missing_resource.txt
if ([response isNotFound]) {
NSLog(@"The resource path '%@' was not found.", [request resourcePath]);
}
}
}

@end

Link: http://liebke.github.com/restkit-github-client-example

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.