Cannot initialize a variable of type 'NSArray<NSValue *> *__strong' with an rvalue of type 'const simd_float2 *'
时间: 2024-02-03 18:03:59 浏览: 32
这个错误提示的意思是无法用 `const simd_float2 *` 类型的 rvalue 初始化一个类型为 `NSArray<NSValue *> *__strong` 的变量。
要解决这个问题,你需要将 `const simd_float2 *` 转换成 `NSArray<NSValue *>` 类型。可以使用 `NSArray` 的类方法 `arrayWithObjects:count:` 将 C 数组转换为 `NSArray` 对象,并使用 `NSValue` 的类方法 `valueWithBytes:objCType:` 将 `simd_float2` 转换为 `NSValue` 对象。
以下是一个示例代码:
```
const simd_float2 arr[] = {simd_make_float2(1.0, 2.0), simd_make_float2(3.0, 4.0)};
NSUInteger count = sizeof(arr) / sizeof(simd_float2);
NSMutableArray<NSValue *> *values = [NSMutableArray arrayWithCapacity:count];
for (NSUInteger i = 0; i < count; i++) {
NSValue *value = [NSValue valueWithBytes:&arr[i] objCType:@encode(simd_float2)];
[values addObject:value];
}
NSArray<NSValue *> *array = [NSArray arrayWithArray:values];
```
这样就能够将 `const simd_float2 *` 数组转换成 `NSArray<NSValue *>` 对象了。