NSArray 中单个索引的多个对象

发布于 2024-09-25 04:54:53 字数 34 浏览 1 评论 0原文

是否可以在 NSArray 中为单个索引存储多个对象?

Is it possible to store multiple objects for a single index in an NSArray?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海的爱人是光 2024-10-02 04:54:54

是的,您可能只想拥有一个由 NSMutableArray 组成的 NSArray。然后你可以这样调用:

[[array objectAtIndex:2] addObject:obj];

或者

[[array objectAtIndex:2] objectAtIndex:1];

Yes, you probably just want to have an NSArray of NSMutableArrays. You can then call something like this:

[[array objectAtIndex:2] addObject:obj];

or

[[array objectAtIndex:2] objectAtIndex:1];
爱的那么颓废 2024-10-02 04:54:54

我不确定您希望多个对象的动态程度如何。创建一个具有多个对象属性的非常简单的类怎么样?
我正在考虑一个结构体,但我不认为 NSArray 像指针对象。

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

@interface myCompound : NSObject
{
}

@property (nonatomic,strong) NSColor* colour;
@property (nonatomic,strong) NSRegularExpression* expression;

@end

@implementation myCompound

@synthesize colour;
@synthesize expression;

@end

并使用它作为 NSArray 的元素类型
NSArray* myArray;

I'm not sure how dynamic you want the multiple objects to be. How about creating a very simple class with properties of the multiple objects?
I was thinking about a struct but I don't think NSArrays like pointer objects.

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

@interface myCompound : NSObject
{
}

@property (nonatomic,strong) NSColor* colour;
@property (nonatomic,strong) NSRegularExpression* expression;

@end

@implementation myCompound

@synthesize colour;
@synthesize expression;

@end

And use this as the element type for NSArray
NSArray<myCompound*>* myArray;

凉薄对峙 2024-10-02 04:54:53

当然,有很多方法可以做到这一点,最常见的是为每个数组元素分配一个字典

Sure there are many ways to do this with the most common being to assign a dictionary to each array element

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文