Ios 在要保存的数组中保存自定义类

Ios 在要保存的数组中保存自定义类,ios,objective-c,arrays,Ios,Objective C,Arrays,我正在创建一个应用程序,该应用程序将创建一个表单,然后用户将填写该表单并保存以供以后使用 @interface DataModel : NSObject @property (strong, nonatomic) NSString *whiskeyName; @property (strong, nonatomic) NSNumber *whiskeyRating; @property (strong, nonatomic) NSString *whiskeyColor; @property

我正在创建一个应用程序,该应用程序将创建一个表单,然后用户将填写该表单并保存以供以后使用

@interface DataModel : NSObject

@property (strong, nonatomic) NSString *whiskeyName;
@property (strong, nonatomic) NSNumber *whiskeyRating;
@property (strong, nonatomic) NSString *whiskeyColor;
@property (strong, nonatomic) NSString *whiskeyNose;
@property (strong, nonatomic) NSString *whiskeyFlavors;
@property (strong, nonatomic) NSString *whiskeyFinish;
@property (strong, nonatomic) NSString *whiskeyNotes;

该应用程序将存储这些表单的多个副本(想想苹果的Notes应用程序)。我已经创建了一个由
NSStrings
NSNumbers
组成的类,但我很难找到一种方法将它们保存到
NSArray
以便以后访问。我刚开始玩弄核心数据,但我发现的所有东西都只保存一个表单。如何在数组中保存一个类的多个版本,以便打开和编辑以供以后使用?如果问题不明确,很抱歉,但我的头撞到了墙上,很难找到一个有效的解决方案。

如果我理解正确,您已将NSObject子类化,并希望将此类的多个实例保存到一个数组中?如果是这种情况,那么可变数组应该能够容纳任何对象:

// .m file
#import "DataModel.h"

@interface YourViewController
    @property (strong, nonatomic) NSMutableArray *myArray;
@end

@implementation YourViewController

- (void) viewDidLoad {
    NSMutableArray *myArray = [[NSMutableArray alloc] initWithCapacity:numberOfObjectsToStore];

    DataModel *myClassInstance1 = [[DataModel alloc] init];
    myClassInstance1.whiskeyName= @"somevalue";
    myClassInstance1.whiskeyRating= 5;

    DataModel *myClassInstance2 = [[DataModel alloc] init];
    myClassInstance2.whiskeyName= @"someothervalue";
    myClassInstance2.whiskeyRating= 2;

    [myArray addObject:myClassInstance1];
    [myArray addObject:myClassInstance2];

}