<转>RestKit在iOS项目中的使用,包含xcode配置说明

摘要:
终于在最后的关头找了一篇英文的较为权威的文档才发现自己的问题出在一个很细节的地方。下面就总结一下怎么在xcode项目中使用Restkit。现在我们进行一个简单的测试:在applicationDidFinishLaunching函数中添加如下代码:-applicationDidFinishLaunching:applicationwithOptions:options{RKClient*client=[RKClientclientWithBaseURL:@"http://restkit.org"];}测试如下:#import//HerewedeclarethatweimplementtheRKRequestDelegateprotocol//CheckoutRestKit/Network/RKRequest.hforadditionaldelegatemethods//thatareavailable.@interfaceRKRequestExamples:NSObject{}@end@implementationRKRequestExamples-sendRequests{//PerformasimpleHTTPGETandcallmebackwiththeresults[[RKClientsharedClient]get:@"/foo.xml"delegate:self];//SendaPOSTtoaremoteresource.Thedictionarywillbetransparently//convertedintoaURLencodedrepresentationandsentalongastherequestbodyNSDictionary*params=[NSDictionarydictionaryWithObject:@"RestKit"forKey:@"Sender"];[[RKClientsharedClient]post:@"/other.json"params:paramsdelegate:self];//DELETEaremoteresourcefromtheserver[[RKClientclient]delete:@"/missing_resource.txt"delegate:self];}-request:requestdidLoadResponse:response{if{//HandlingGET/foo.xmlif{//Success!
本文转载至http://www.cnblogs.com/visen-0/archive/2012/05/03/2480693.html

最近在iPhone工程中添加RestKit并编译,但是由于之前找了很多不靠谱的说明文档,导致编译了一天也没有通过编译,总报出莫名其妙的错误。终于在最后的关头找了一篇英文的较为权威的文档才发现自己的问题出在一个很细节的地方。结论就是:不靠谱的文档害死人。

下面就总结一下怎么在xcode项目中使用Restkit。

1. 下载RestKit源码,到官网去下,下载后解压源码,不做过多解释;

2. 在xcode中建立一个iOS项目,并在项目的文件夹中复制一份RestKit源码

1

3. 将RestKit中的RestKit.xcodeproj文件拖动到xcode的资源管理器中

2

4. 选择最顶层的工程,然后选择中间栏PROJECT中的那个项目,进行设置

(1)找到Build Setting中的Header Search Path,然后设置其值为"$(SOURCE_ROOT)/RestKit/Build"

3

(2)找到Build Setting中的Library Search Path,然后设置其值为"$(SOURCE_ROOT)/RestKit/Build/$(BUILD_STYLE)-$(PLATFORM_NAME)"

4

5. 选择中间栏TARGET中的一项,然后点击Build Phase选项卡,在Target Dependence中添加RestKit

5

6. 在Link Binary with Libraries中添加如下包名称:

libRestKitCoreData.a

libRestKitJSONParserYAJL.a

libRestKitNetwork.a

libRestKitObjectMapping.a

libRestKitSupport.a

CFNetwork.framework

CoreData.framework

MobileCoreServices.framework

SystemConfiguration.framework

6

7. 头文件中引入

#import <RestKit/RestKit.h>

#import <RestKit/CoreData/CoreData.h>

点击编译,如果没问题的话就编译成功了。

现在我们进行一个简单的测试:

在applicationDidFinishLaunching函数中添加如下代码:

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

测试如下:

复制代码
复制代码
#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
复制代码
复制代码

附上英文原文网址:http://liebke.github.com/restkit-github-client-example

免责声明:文章转载自《&amp;lt;转&amp;gt;RestKit在iOS项目中的使用,包含xcode配置说明》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇git push rejectedOracle的表空间quota详解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Python3自定义http/https请求拦截mitmproxy脚本

[本文出自天外归云的博客园] 脚本内容 代码如下: from mitmproxy importhttp, ctx from multiprocessing importLock classFilter: def __init__(self, filter_info): self.log_info = "" s...

Vue 3 组件开发:搭建基于SpreadJS的表格编辑系统(功能拓展)

通过环境搭建和组件集成,我们学会使用 Vite 和 SpreadJS ,将在线Excel的编辑功能集成在Vue 3项目中。 本章,我将带领大家继续扩展 Vue 3 这个项目原型,实现数据绑定、模板文件导入/更新/导出和数据透视表等功能,本章的实现思路与上一篇“组件集成”基本类似。 设计思路 · 同时创建SpreadJS 和Designer(表格编辑器)两个...

安装glib脚本

记录下安装脚本安装glib的过程。 情况是:需要安装libnice,但是libnice依赖glib,glib需要meson和ninja编译生成,而meson需要python3.5以上。 所以就有了下面的安装脚本。 这种情况适用于需要自动化编译。尽可能的不用yum的情况,其实还是在安装python3.6的时候还是用了yum。 里面的注释可以自己选择去掉。我添...

xcode 自动添加注释,生成文档

一、自动生成注释代码        添加一个快捷键,生成 注释代码        ThisService 下载连接:http://wafflesoftware.net/thisservice/          Doxygen.rb 下载连接:http://www.brokenrul.es/blog/wp-content/uploads/2011/03/...

解决xcode打开时loading假死的问题

症状如下: 点击打开xcode后,就一直会看到loading,但是CPU消耗很高,基本上就是死了(动弹不得),通过活动监测器看到xcode显示为“未响应”,以为是安装程序的问题,结果选中xcode拉到废纸篓中,重新下载安装,还是一样的总是,都快崩溃了。 出错原因:可能是上次强制退出时保存xcode出错,导致之后每次打开xcode都会加载这个错误的工程,出现...

Android Studio Gradle:Resolvedependencies':app:_debugCompile' 问题解决纪录

问题描述: 第一次使用AndroidStudio打开已经存在的AndroidStudio项目,卡在Gradle:Resolvedependencies':app_debugCompile'步骤,即使进入了AndroidStudio界面也无法正常下载Gradle依赖,无法编译运行。 1.首先确认gradle依赖都声明在app下的build.gradle中,而...