我遇到了一个全新项目的问题.RestKit和Facebook SDK都会出现此问题.奇怪的是SwiftyJSON工作得很好.我创建了一个全新的swift项目和一个Podfile:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'test-fb-swift4' do
pod "FBSDKCoreKit"
pod 'SwiftyJSON', '~> 2.1'
pod 'RestKit', :inhibit_warnings => true
end
target 'test-fb-swift4Tests' do
end
Run Code Online (Sandbox Code Playgroud)
创建该文件后,我运行pod install并使用test-fb-swift4.xcworkspace文件重新打开xcode.
现在我的控制器里面放了一个导入RestKit,我得到错误没有这样的模块'RestKit'.我已经尝试了许多不同的方法来格式化Podfile,甚至是非常简单的版本,例如:
source 'https://github.com/CocoaPods/Specs.git'
pod 'RestKit'
Run Code Online (Sandbox Code Playgroud)
我尝试添加和删除use_frameworks,有和没有目标.有和没有:inhibit_warnings.
我正在运行CocoaPods 0.36.4并尝试了最新的rc构建,同样的交易.另一个项目的Objective-C版本运行正常.这是我使用Swift的第一个项目,我坚持这个问题.
我正在编写一个iPhone应用程序,最后我决定使用RestKit作为连接REST服务的框架.
我想构建的方式是让我的应用程序中的控制器与RestKit完全无关.例如.如果我有一个登录屏幕,在通常的RestKit场景中(基于示例程序以及RestKit开发人员创建的一些博客条目),您将让控制器实现RKRequestDelegate协议并使用RKClient在Controller传递中调用服务自我(控制者)作为代表.我想隐藏用户开发控制器和视图.
我在想的是以下内容.我将有一个登录用户的LoginService.会有协议LoginServiceDelegate,它有两个成功和失败的方法.Controller可以实现LoginServiceDelegate并在LoginService中调用login方法并获得成功或失败回调.但是要做到这一点,我需要一些方法让我的LoginService将调用委托给控制器.RestKit不允许我这样做,这是我能够通过使用LoginServiceDelegate初始化LoginService,将该委托存储为属性并在成功登录或失败时在委托中调用适当的方法来实现此目的的唯一方法.
这使我的Controller代码库保持最小,并完全隐藏了LoginService的工作方式以及它内部使用的框架.委托人的使用也使Controller与模型分离,因此我们有一个很好的MVC.但是我担心Model类保留Controller对象的含义,因为它保留在委托上.
你会如何使用RestKit?如果你认为我的方法很好,你会改变什么来改善它?如果你不喜欢我的方法,那么你会反馈为什么你觉得这不是一个好习惯.
下面的代码片段应该会给你一个更好的主意
@protocol LoginServiceDelegate;
@interface LoginService : NSObject <RKRequestDelegate>{
NSObject<LoginServiceDelegate> *_loginServiceDelegate;
}
@property (retain, nonatomic) NSObject <LoginServiceDelegate> *loginServiceDelegate;
- (id) initWithDelegate:(NSObject<LoginServiceDelegate>*) loginServiceDelegate;
- (void) login:(NSString *)username withPassword:(NSString *)password;
@end
@protocol LoginServiceDelegate
@optional
- (void) loginSuccess:(LoginInfo *) loginInfo;
- (void) loginFailure:(NSString *) message;
@end
Run Code Online (Sandbox Code Playgroud)
干杯!!!
我"pod update",我的RestKit版本现在是0.25.0,我的RKValueTransformers是1.1.2,并且找不到错误"RKObjectMapping.h".
RestKit在新版本中的变化是什么,我检查它的github无法找到任何东西.
以下步骤可以重现错误:
1)创建一个新项目
2)pod init
Podfile看起来像:
platform :ios, '8.3'
#pod 'RestKit', '~> 0.20.0'
#pod 'RestKit', '~> 0.24.1'
pod 'RestKit'
Run Code Online (Sandbox Code Playgroud)
在所有不同版本的情况下,问题都是一样的
3)打开.xcworkspace
4)在viewcontroller.m中
#import <RestKit/ObjectMapping/RKObjectMapping.h>
#import <RestKit/ObjectMapping/RKRelationshipMapping.h>
#import <RestKit/Network/RKResponseDescriptor.h>
#import <RestKit/Network/RKObjectRequestOperation.h>
#import <RestKit/Support/RKLog.h>
#import <RestKit/CoreData/RKEntityMapping.h>
#import <RestKit/Network/RKObjectManager.h>
Run Code Online (Sandbox Code Playgroud)
要么
#import "RKObjectMapping.h"
#import "RKRelationshipMapping.h"
#import "RKResponseDescriptor.h"
#import "RKObjectRequestOperation.h"
#import "RKLog.h"
#import "RKEntityMapping.h"
#import "RKObjectManager.h"
Run Code Online (Sandbox Code Playgroud)
错误仍然存在:在RestKit Pod的文件中找不到"RKObjectMapping.h"
注意:我使用的是Xcode 7-beta5,Objective-C
我正在尝试调试RestKit对象映射,并注意到RKLogDebug整个代码都有调用,但似乎某个宏未定义.我该如何启用它?
restkit以不同的方式使用oauth2协议,我需要更改代码以便能够以我的方式使用它:
从:
// OAuth 2 valid request
if (self.authenticationType == RKRequestAuthenticationTypeOAuth2) {
NSString *authorizationString = [NSString stringWithFormat:@"OAuth2 %@", self.OAuth2AccessToken];
[_URLRequest setValue:authorizationString forHTTPHeaderField:@"Authorization"];
}
Run Code Online (Sandbox Code Playgroud)
至:
// OAuth 2 valid request
if (self.authenticationType == RKRequestAuthenticationTypeOAuth2) {
NSString *authorizationString = [NSString stringWithFormat:@"Bearer %@", self.OAuth2AccessToken];
[_URLRequest setValue:authorizationString forHTTPHeaderField:@"Authorization"];
}
Run Code Online (Sandbox Code Playgroud)
使用"Bearer"而不是"Oauth2"....
我正在使用CocoaPods在我的项目中导入restkit.
我可以在github上分叉Restkit存储库并通过CocoaPod而不是官方版本使用fork吗?
我一直在尝试使用Restkit库的0.20.3版本.最近出现了一个错误,我无法弄清楚如何解决.它是以下内容:
在'RKObjectManager*'类型的对象上找不到属性'managedObjectStore'
它发生在包含的行
objectManager.managedObjectStore = managedObjectStore;
下面列出了我的一小段代码,以帮助识别.我使用CocoaPods来安装所有必需的库,一切似乎都正确链接.
#import "AppDelegate.h"
#import <RestKit/RestKit.h>
#import <RestKit/CoreData.h>
#import <CoreData/CoreData.h>
#import <RestKit/ObjectMapping.h>
#import "Temperature.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
//let AFNetworking manage the activity indicator
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
// Override point for customization after application launch.
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://grid.no-ip.biz/grid"]];
NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Grideye" ofType:@"momd"]];
//Initialize managed object store
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL ] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
objectManager.managedObjectStore = …Run Code Online (Sandbox Code Playgroud) 我想知道.. Restkit一直显示可达性信息,在我使用它时请求信息.这会自动停止在生产版本中,还是我需要做些什么来阻止它们显示设置RKLog级别?
谢谢
我希望看到iPhone的JSON输入/输出.我怎样才能做到这一点?
我需要设置使用NSLog()(以及在哪里)?或者,设置RestKit日志记录级别(到什么)?
我试图让RestKit建造和工作,我正在失去我的头发.我得到了可怕的"词法或预处理器问题:未找到RestKit/RestKit.h文件"消息.我使用Xcode 4.2,我的项目适用于iOS.
之前,我的调试模式与RestKit 0.9.0完美配合.然后我在尝试存档时遇到了问题.在阅读了这个论坛并尝试了一些解决方案之后,我决定升级到0.10.0,希望能解决这个问题.
现在,我的项目甚至没有在调试模式下构建,我得到相同的RestKit/RestKit.h文件未找到错误.
我在Header搜索路径下有这个:"$(BUILT_PRODUCTS_DIR)/../../ Headers".你能否建议(适用于0.10.0版本):1)RestKit的物理位置应该在哪里?(这可能没关系,但哪一个对你有用 - 希望我可以镜像你的设置)2)我试图将我的标题搜索路径指向"/ Developer/Library/RestKit-RestKit-69adee9 /",然后再转到" /开发/库/ RestKit-RestKit-69adee9 /编译"
彻底困惑和沮丧..
编辑1:几个小时后,我放弃了.Nuked我的项目.创建了一个新项目.重新创建文件(从prev项目复制粘贴).现在"RestKit not found"错误消失了!但现在,我收到了另一个错误:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_RKObjectMapping", referenced from:
objc-class-ref in myclassname1.o
"_OBJC_CLASS_$_RKObjectManager", referenced from:
objc-class-ref in myclassname2.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我检查并确保我没有添加RestKit.framework ...我不知道为什么现在发生clang错误
EDIT2: libRestKit.a是红色的.根据https://github.com/RestKit/RestKit/wiki/Installation-Troubleshooting可以,只是为了它,我删除了所有链接的依赖项.删除了"其他链接器标志".关闭并重新打开Xcode.把它们全部放回去.那个错误消失了.也许我错过了导致clang错误的框架.但我检查和双重检查的可能性极小.它现在有效.
它在调试模式下构建和存档.我还没有尝试过分发模式.
编辑3: Apple第一次批准我的应用程序,它是现场直播!我仍然不知道是什么原因引起了这个问题.Nuking现有项目并创建新项目并复制旧文件(并定期检查构建是否通过)不能成为解决方案.所以我打开这个问题.
我正在学习restkit api.我发现了一个非常好的Raywenderlich restkit教程.但它与Restkit 0.10.1集成在一起.我想学习一个RestKit-0.20.0-pre6.如果任何人在iOS中有这样的好教程.请分享.提前致谢.
restkit ×10
ios ×6
objective-c ×4
cocoapods ×3
iphone ×3
clang ×1
cocoa-touch ×1
header ×1
logging ×1
rest ×1
restkit-0.20 ×1
swift ×1