为什么 return on function 发出 SIGBART 信号?
Why return on function make a SIGBART signal?
我是 objective c 的新手。
我不明白为什么我的函数不起作用,它在函数的 return 上产生错误 SIGBART。
+ (NSArray*) jsonToArray:(NSString*)jsonString
{
id mappedObj = nil;
RKObjectMappingProvider* mapProv = [[RKObjectMappingProvider alloc] init];
RKObjectMapping* answerMapping = [SMAnswersWrapper entityMappingForSerializer];
answerMapping.objectClass = [NSMutableDictionary class];
[mapProv setSerializationMapping:answerMapping forClass:[SMAnswersWrapper class]];
RKObjectMapping *proofsEntityMapping = [SMEntityArrayWrapper entityMappingWithContentMapping:answerMapping];
[mapProv setMapping:proofsEntityMapping forKeyPath:@""];
if (jsonString)
{
id obj = [jsonString objectFromJSONString];
if (obj)
{
RKObjectMapper* mapper = [[RKObjectMapper alloc] initWithObject:obj mappingProvider:mapProv];
RKObjectMappingResult* res = [mapper performMapping];
mappedObj = [res asCollection];
[mapper release];
}
}
[mapProv release];
return [[[mappedObj content] retain] autorelease];
}
错误位置在这一行:
return [[[mappedObj content] retain] autorelease];
谢谢。
编辑
我发现我的错误,我无法访问 [[[mappedObj content] retain] autorelease];
的内容我不得不投射 mappedObj。
尝试以下操作:
+ (NSArray*) jsonToArray:(NSString*)jsonString
{
id mappedObj = nil;
RKObjectMappingProvider* mapProv = [[RKObjectMappingProvider alloc] init];
RKObjectMapping* answerMapping = [SMAnswersWrapper entityMappingForSerializer];
answerMapping.objectClass = [NSMutableDictionary class];
[mapProv setSerializationMapping:answerMapping forClass:[SMAnswersWrapper class]];
RKObjectMapping *proofsEntityMapping = [SMEntityArrayWrapper entityMappingWithContentMapping:answerMapping];
[mapProv setMapping:proofsEntityMapping forKeyPath:@""];
if (jsonString)
{
id obj = [jsonString objectFromJSONString];
if (obj)
{
RKObjectMapper* mapper = [[RKObjectMapper alloc] initWithObject:obj mappingProvider:mapProv];
RKObjectMappingResult* res = [mapper performMapping];
mappedObj = [res asCollection];
[mapper release];
}
}
[mapProv release];
if (mappedObj)
{
return [[[mappedObj content] retain] autorelease];
}
return [NSArray array];
}
在您的代码中,如果 jsonString
或 obj
为 nil,则不会初始化 mappedObj。这种情况可能会导致访问 [mappedObj content]
.
时崩溃
试试这个,这会对你有帮助.....
我发现我的错误,我无法访问位于 [[[mappedObj content] retain] autorelease];
的内容我不得不投射 mappedObj。
我是 objective c 的新手。 我不明白为什么我的函数不起作用,它在函数的 return 上产生错误 SIGBART。
+ (NSArray*) jsonToArray:(NSString*)jsonString
{
id mappedObj = nil;
RKObjectMappingProvider* mapProv = [[RKObjectMappingProvider alloc] init];
RKObjectMapping* answerMapping = [SMAnswersWrapper entityMappingForSerializer];
answerMapping.objectClass = [NSMutableDictionary class];
[mapProv setSerializationMapping:answerMapping forClass:[SMAnswersWrapper class]];
RKObjectMapping *proofsEntityMapping = [SMEntityArrayWrapper entityMappingWithContentMapping:answerMapping];
[mapProv setMapping:proofsEntityMapping forKeyPath:@""];
if (jsonString)
{
id obj = [jsonString objectFromJSONString];
if (obj)
{
RKObjectMapper* mapper = [[RKObjectMapper alloc] initWithObject:obj mappingProvider:mapProv];
RKObjectMappingResult* res = [mapper performMapping];
mappedObj = [res asCollection];
[mapper release];
}
}
[mapProv release];
return [[[mappedObj content] retain] autorelease];
}
错误位置在这一行:
return [[[mappedObj content] retain] autorelease];
谢谢。
编辑
我发现我的错误,我无法访问 [[[mappedObj content] retain] autorelease];
的内容我不得不投射 mappedObj。
尝试以下操作:
+ (NSArray*) jsonToArray:(NSString*)jsonString
{
id mappedObj = nil;
RKObjectMappingProvider* mapProv = [[RKObjectMappingProvider alloc] init];
RKObjectMapping* answerMapping = [SMAnswersWrapper entityMappingForSerializer];
answerMapping.objectClass = [NSMutableDictionary class];
[mapProv setSerializationMapping:answerMapping forClass:[SMAnswersWrapper class]];
RKObjectMapping *proofsEntityMapping = [SMEntityArrayWrapper entityMappingWithContentMapping:answerMapping];
[mapProv setMapping:proofsEntityMapping forKeyPath:@""];
if (jsonString)
{
id obj = [jsonString objectFromJSONString];
if (obj)
{
RKObjectMapper* mapper = [[RKObjectMapper alloc] initWithObject:obj mappingProvider:mapProv];
RKObjectMappingResult* res = [mapper performMapping];
mappedObj = [res asCollection];
[mapper release];
}
}
[mapProv release];
if (mappedObj)
{
return [[[mappedObj content] retain] autorelease];
}
return [NSArray array];
}
在您的代码中,如果 jsonString
或 obj
为 nil,则不会初始化 mappedObj。这种情况可能会导致访问 [mappedObj content]
.
试试这个,这会对你有帮助.....
我发现我的错误,我无法访问位于 [[[mappedObj content] retain] autorelease];
的内容我不得不投射 mappedObj。