gpt4 book ai didi

objective-c - 如何向集合添加不透明类型

转载 作者:行者123 更新时间:2023-12-03 17:37:26 24 4
gpt4 key购买 nike

如何将不透明类型添加到 cocoa 中的集合中?

我收到了编译器警告(显然,因为不透明类型不是对象):

CGColorSpaceRef colorSpace;
NSArray *myArray = [NSArray arrayWithObject:colorSpace];

最佳答案

您可以使用 NSValue 类将不透明类型包装在对象中。来自 here :

An NSValue object is a simple container for a single C or Objective-C data item. It can hold any of the scalar types such as int, float, and char, as well as pointers, structures, and object ids. The purpose of this class is to allow items of such data types to be added to collections such as instances of NSArray and NSSet, which require their elements to be objects. NSValue objects are always immutable.

关于objective-c - 如何向集合添加不透明类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/504174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com