- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试映射到一个对象,但一直在获取
[<ItemObject 0x100353710> valueForUndefinedKey:]: this class is not key value coding-compliant for the key uid.
ItemObject.h
@interface ItemObject : NSObject
@property (nonatomic, retain) NSNumber * uid;
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * itemType;
@end
ItemObject.m
@implementation ItemObject
@dynamic uid;
@dynamic title;
@dynamic itemType;
@end
方法
+ (void)searchFeatureById:(NSString *)searchId
{
NSLog(@"Search Feature By ID: %@", searchId);
RKObjectMapping *itemMapping = [RKObjectMapping mappingForClass:[ItemObject class]];
[itemMapping addAttributeMappingsFromDictionary:@{
@"id": @"uid",
@"name": @"title",
@"item_type": @"itemType"
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:itemMapping pathPattern:nil keyPath:@"data" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];
// The entire value at the source key path containing the errors maps to the message
[errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"errorMessage"]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError);
// Any response in the 4xx status code range with an "errors" key path uses this mapping
RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping pathPattern:nil keyPath:@"error_description" statusCodes:statusCodes];
RKObjectManager *manager = [RKObjectManager sharedManager];
NSLog(@"HTTP Client: %@", manager.HTTPClient);
[manager addResponseDescriptorsFromArray:@[ responseDescriptor, errorDescriptor ]];
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"false", @"with_lock"
, nil];
NSString *path = [NSString stringWithFormat:@"/api/v1/features/%@", searchId];
NSLog(@"Manager: %@", manager);
[manager getObjectsAtPath:path parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(@"Results: %@", result);
// Handled with articleDescriptor
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
// Transport error or server error handled by errorDescriptor
NSLog(@"Error: %@", [error localizedDescription]);
NSAlert *alert = [NSAlert alertWithMessageText:@"Error" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", [error localizedDescription]];
[alert runModal];
}];
}
JSON 响应
{
"data": {
"id": 1961,
"item_type": "features",
"assigned_to": {
"id": 106
},
"parent": {
"id": 0
},
"priority": {
"id": 3
},
"project": {
"id": 62
},
"release": {
"id": 180
},
"reported_by": {
"id": 106
},
"reported_by_customer_contact": {
"id": 0
},
"status": {
"id": 6
},
"workflow_step": {
"id": 10
},
"actual_duration": {
"duration": 0,
"time_unit": {
"id": 2
}
},
"estimated_duration": {
"duration": 8,
"time_unit": {
"id": 2
}
},
"remaining_duration": {
"duration": 0,
"time_unit": {
"id": 2
}
},
"percent_complete": 0,
"archived": false,
"publicly_viewable": false,
"completion_date": "1899-01-01T07:00:00Z",
"due_date": "1899-01-01T07:00:00Z",
"start_date": "2013-03-11T07:00:00Z",
"description": "Create Login GUI",
"name": "Login View",
"notes": "",
"number": "1961",
"build_number": "",
"custom_fields": {
"custom_157": true,
"custom_180": "",
"custom_174": "",
"custom_181": false,
"custom_179": "",
"custom_182": "",
"custom_186": false,
"custom_156": 0,
"custom_161": "",
"custom_163": "",
"custom_164": "",
"custom_165": "",
"custom_167": "",
"custom_185": []
}
}
}
崩溃
(
0 CoreFoundation 0x00007fff8d39bf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8a7b2d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d4261b9 -[NSException raise] + 9
3 Foundation 0x00007fff9716c703 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 240
4 Foundation 0x00007fff970a338e _NSGetUsingKeyValueGetter + 108
5 Foundation 0x00007fff970a3315 -[NSObject(NSKeyValueCoding) valueForKey:] + 392
6 Foundation 0x00007fff970c2da2 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 348
7 RestKit 0x0000000100079675 -[RKMappingOperation shouldSetValue:atKeyPath:] + 85
8 RestKit 0x000000010007ad9f -[RKMappingOperation applyAttributeMapping:withValue:] + 2079
9 RestKit 0x000000010007c028 -[RKMappingOperation applyAttributeMappings:] + 1752
10 RestKit 0x00000001000832e0 -[RKMappingOperation main] + 3200
11 Foundation 0x00007fff970c56b4 -[__NSOperationInternal start] + 705
12 RestKit 0x000000010006c84e -[RKMapperOperation mapRepresentation:toObject:atKeyPath:usingMapping:metadata:] + 1870
13 RestKit 0x000000010006afbb -[RKMapperOperation mapRepresentation:atKeyPath:usingMapping:] + 1883
14 RestKit 0x000000010006da20 -[RKMapperOperation mapRepresentationOrRepresentations:atKeyPath:usingMapping:] + 832
15 RestKit 0x000000010006e26e -[RKMapperOperation mapSourceRepresentationWithMappingsDictionary:] + 1966
16 RestKit 0x000000010006ebbf -[RKMapperOperation main] + 1375
17 Foundation 0x00007fff970c56b4 -[__NSOperationInternal start] + 705
18 RestKit 0x00000001000e8f1c -[RKObjectResponseMapperOperation performMappingWithObject:error:] + 1116
19 RestKit 0x00000001000e7347 -[RKResponseMapperOperation main] + 2055
20 Foundation 0x00007fff970c56b4 -[__NSOperationInternal start] + 705
21 Foundation 0x00007fff970d8912 ____NSOQSchedule_block_invoke_2 + 124
22 libdispatch.dylib 0x00007fff8abe1a82 _dispatch_call_block_and_release + 18
23 libdispatch.dylib 0x00007fff8abe2961 _dispatch_worker_thread2 + 255
24 libsystem_c.dylib 0x00007fff9054c3da _pthread_wqthread + 316
25 libsystem_c.dylib 0x00007fff9054db85 start_wqthread + 13
使用 RestKit 0.20.0-rc1 进行 Mac OS X 开发
我做错了什么?如果我添加/删除对象属性,它会为新参数抛出相同的键/值错误。这让我相信这不是我的对象的东西,而是键路径?
更新
它跳转到RKMappingOperation.m
文件第 356 行。
- (BOOL)shouldSetValue:(id *)value atKeyPath:(NSString *)keyPath
{
id currentValue = [self.destinationObject valueForKeyPath:keyPath]; //<-- this line here
if (currentValue == [NSNull null]) {
currentValue = nil;
}
每个@noa 更新 2
2013-03-14 10:11:51.012 Project[55798:6a03] Destination Class: ItemObject
2013-03-14 10:11:51.012 Project[55798:6a03] Destination Class Super: NSObject
添加
[self.destinationObject objectForKey:@"uid"];
日志
2013-03-14 10:16:08.030 Project[55836:2203] -[ItemObject objectForKey:]: unrecognized selector sent to instance 0x103437e80
最佳答案
您在实现中使用的 @dynamic
指令告诉编译器不为该属性生成方法。由于这些方法不存在,因此您的类不符合这些键的键值对。 (即 RestKit 正在尝试调用 uid
方法,但它不存在。)
你应该:
uid
和 setUid:
关于objective-c - RestKit 模型对象引发 -valueForUndefinedKey : for a synthesized property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15396024/
我遵循了一本名为“Sitepoint Full Stack Javascript with MEAN”的书中的教程,我刚刚完成了第 6 章,应该已经创建了一个带有“数据库”的“服务器”。数据库只不过是
在 Jquery 中,我创建两个数组,一个嵌入另一个数组,就像这样...... arrayOne = [{name:'a',value:1}, {name:'b',value:2}] var arra
这个问题在这里已经有了答案: What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wa
我被放在别人的代码上,有一个类用作其他组件的基础。当我尝试 ng serve --aot(或 build --prod)时,我得到以下信息。 @Component({ ...,
我正在测试一些代码,并使用数据创建了一个 json 文件。 问题是我在警报中收到“[object Object],[object Object]”。没有数据。 我做错了什么? 这是代码:
我想打印 [object Object],[object Object] 以明智地 "[[{ 'x': '1', 'y': '0' }, { 'x': '2', 'y': '1' }]]"; 在 ja
我有一个功能 View ,我正在尝试以特殊格式的方式输出。但我无法让列表功能正常工作。 我得到的唯一返回是[object Object][object Object] [object Object]
在使用优秀的 Sim.js 和 Three.js 库处理 WebGL 项目时,我偶然发现了下一个问题: 一路走来,它使用了 THREE.Ray 的下一个构造函数: var ray = new THRE
我正在使用 Material UI 进行多重选择。这是我的代码。 {listStates.map(col => (
我的代码使用ajax: $("#keyword").keyup(function() { var keyword = $("#keyword").val(); if (keyword.
我遇到了下一个错误,无法理解如何解决它。 Can't resolve all parameters for AuthenticationService: ([object Object], ?, [o
我正在尝试创建一个显示动态复选框的表单,至少应选中其中一个才能继续。我还需要获取一组选中的复选框。 这是组件的代码: import { Component, OnInit } from '@angul
我正在开发 NodeJs 应用程序,它是博客应用程序。我使用了快速验证器,我尝试在 UI 端使用快速闪存消息将帖子保存在数据库中之前使用闪存消息验证数据,我成功地将数据保存在数据库中,但在提交表单后消
我知道有些人问了同样的问题并得到了解答。我已经查看了所有这些,但仍然无法解决我的问题。我有一个 jquery snipet,它将值发送到处理程序,处理程序处理来自 JS 的值并将数据作为 JSON 数
我继承了一个非常草率的项目,我的任务是解释为什么它不好。我注意到他们在整个代码中都进行了这样的比较 (IQueryable).FirstOrDefault(x => x.Facility == fac
我只是在删除数组中的对象时偶然发现了这一点。 代码如下: friends = []; friends.push( { a: 'Nexus', b: 'Muffi
这两个代码片段有什么区别: object = nil; [object release] 对比 [object release]; object = nil; 哪个是最佳实践? 最佳答案 object
我应该为其他人将从中继承的第一个父对象传递哪个参数,哪个参数更有效 Object.create(Object.prototype) Object.create(Object) Object.creat
我在不同的对象上安排不同的选择器 [self performSelector:@selector(doSmth) withObject:objectA afterDelay:1]; [self per
NSLog(@"%p", &object); 和 NSLog(@"%p", object); 有什么区别? 两者似乎都打印出一个内存地址,但我不确定哪个是对象的实际内存地址。 最佳答案 这就是我喜欢的
我是一名优秀的程序员,十分优秀!