无法获取大小为16的值.类型编码为{?={CGPoint=dd}d}预计为24字节



尝试从NSValue:

获取CGPoint时出现此错误

"无法获取大小为16的值。类型编码为{?={CGPoint=dd}d}预计为24字节">

for (NSValue *p in array) {
CGPoint pointValue = p.CGPointValue; //Here appears this error
}
for (NSValue *p in array) {
CGPoint pointValue = [p CGPointValue]; //Here appears this error too
}

NSValue是从库中创建的,不能访问。

编辑1打印p.objCType结果为:{CGPoint=dd}

编辑2打印数组结果为:

2021-09-09 16:04:04.251526+0200 App[4964:674948] (
"{length = 24, bytes = 0xa3b27988de206940eb42b35cc9586740000000000000f03f}",
"{length = 24, bytes = 0x33b2fe8e136f6840ace8651ab5b967409dc9d7ee7b0bef3f}",
"{length = 24, bytes = 0xc154b1089cdd6740ace8651ab5b96740b28e3f23264dea3f}",
"{length = 24, bytes = 0x580edb282aeb6640d62444f11779674016af93916f39e63f}",
"{length = 24, bytes = 0xf581a96211b865401f0e49e9040867404ded927b8a12e33f}",
"{length = 24, bytes = 0x1324e1e2ce74644087a474027c66664034f3481fe7b4e13f}",
"{length = 24, bytes = 0x3523ebef38116340ef3aa01bf3c46540778fc387b583e03f}",
"{length = 24, bytes = 0x506850e349ee6140777ef255f4f26440e3d77dc1a4b2e13f}",
"{length = 24, bytes = 0xea7e4c9084db6040ffc14490f52064405e2015fe2ed3e23f}",
"{length = 24, bytes = 0xfe131ad478f25f40a6b2bdeb801e63401999aea8afcae13f}",
"{length = 24, bytes = 0x149fdaad30105f4042147f91332c62404e8f96066287e53f}",
"{length = 24, bytes = 0x1db6515436af5e40ca57d1cb345a6140679349620e80e73f}",
"{length = 24, bytes = 0x1db6515436af5e40529b230636886040f83000f8e0c2e73f}",
"{length = 24, bytes = 0x1db6515436af5e409e9f7c15bd8c5f40153010013271e83f}",
"{length = 24, bytes = 0x0a8863072b715f406fccd347ab495e40869a27450e63e83f}",
"{length = 24, bytes = 0x71675af0b38a604054179ae54ae65c40a7e25a959d81e53f}",
"{length = 24, bytes = 0x5cdc9916fc6c6140fb071341d6e35b4069a857606cb8e53f}",
"{length = 24, bytes = 0xc52270f66d5f62408dda1c31b0015b40d144c5cd8e6ee53f}",
"{length = 24, bytes = 0xaadd0a035d826340cc346a73c4a05a40b88edb022dbbe43f}",
"{length = 24, bytes = 0x0d6a3cc975b56440f670484a27605a40ef474c247756e33f}",
"{length = 24, bytes = 0x6d999b02e2086640f670484a27605a40a01777914c97e23f}",
"{length = 24, bytes = 0x493dbf68cb8c6740f670484a27605a40b2b27e1fcb90e03f}",
"{length = 24, bytes = 0x2a9b87e80dd06840cc346a73c4a05a402a0dc7148d2ae33f}",
"{length = 24, bytes = 0x0cf94f6850136a404f80cfee9b625b4077e1eade1208e33f}",
"{length = 24, bytes = 0xf0b3ea743f366b40bcadc5fec1445c40538bb556a938e33f}",
"{length = 24, bytes = 0xdb282a9b87186c403ff92a7a99065d40e0d373bbad4ee63f}",
"{length = 24, bytes = 0xc9fa3b4e7cda6c40d762ff6022a85d4049ccc22b4fc7e73f}",
"{length = 24, bytes = 0x3b5889d4f36b6d403072860597aa5e40c7cefa969a66e83f}",
"{length = 24, bytes = 0xb7cc4d01719c6d40f11739c3820b5f40ac55403eec59ed3f}"
)

编辑3注意,以这种方式获取值:

CGPoint pointValue = CGPointMake(0, 0);
[p getValue:&pointValue];

在调试模式下工作,但在发布模式下崩溃。

struct { // just here for reference
CGFloat x;
CGFloat y;
} CGPoint; 
struct {
CGPoint p;
double d;
} AssumedEntryType;
typedef AssumedEntryType SomeEntry;

d停留在双。看看你的调试打印,它似乎是一个结构体中的3个值。所以这些数字可以表示任何适合8字节的数据类型(8*3=24)。

内部NSValue实例由一组字节和描述字节名称和结构的C-String配对组成。

如果{?={CGPoint=dd}d}是你描述的NSValue的C字符串,那么你应该能够做以下解码作为NSValue扩展

-(SomeEntry)someEntryValue 
{
SomeEntry entry;

[self getValue:&entry];

return entry;
}

是的,NSValues仍然可以在NSArray中被收集。只要按照C结构体的描述来做就可以了。

Ps:未测试代码…从这个谷歌搜索结果中得到的一些提示或在NSHipster

阅读更多内容编辑:正如Rob指出的…
有不同的列表ObjCType编码和StringFormat说明符

这里NSValue文档

相关内容

  • 没有找到相关文章

最新更新