-2

在 ARC Conversion 期间,Xcode 建议更改

NSMutableData *b = [NSMutableData dataWithBytes:[value getMutableData] 
                                         length:[value length]];

NSMutableData *b = [NSMutableData dataWithBytes:
                       (__bridge const void *)([value getMutableData]) 
                                         length:[value length]];

非 ARC 版本运行良好,但 ARC 版本抛出EXEC_BAD_ACCESS (code=1).

Value 是具有名为 valueObject 的 NSMutableData 属性的自定义对象。GetMutableData 是返回 valueObject 的访问器。

这是一个展平操作,正在添加b到流中。

我需要打电话给发行版或免费版吗?

4

2 回答 2

2

The problem with this is that you're trying to bridge cast a retainable object pointer type to another retainable object pointer type.

You don't need to be casting your getMutableData to a void *. All you need to pass in is a bytes array.

Here's a better explanation: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-objects-restrictions-conversion

This clearly specifies the following:

For example, an Objective-C object pointer shall not be converted to void*.

Here's a better explanation of how to use bridged casts: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#bridged-casts

Some solution to your problem, if I understand correctly, would be that value has a method that returns an NSMutableData object.

NSMutableData *b = [NSMutableData dataWithBytes:[[value getMutableData] bytes] 
                                         length:[value length]];
于 2013-07-19T20:32:26.673 回答
1

Value 是具有名为 valueObject 的 NSMutableData 属性的自定义对象。GetMutableData 是返回 valueObject 的访问器。

考虑到上面的说法,为什么不直接创建一个变量来存储访问器的返回值呢?

NSMutableData *someData = [value getMutableData];
于 2013-07-19T20:15:03.513 回答