1

I have a cocoa application that I'm trying to make scriptable. It has a model class (subclass of NSObject) including an NSArray property, which holds a number of custom "Element" objects of a separate class. I like this design pattern for this application, because the array property for the model class is not needed outside of that class (and thus I don't want to include it in a subclass/category of NSApplication). However, in all of the examples I have seen for creating a scriptable Cocoa application, the top level scripting object is a subclass or category of NSApplication that includes the exposed data as a property or element.

In contrast, I don't have any properties or methods in NSApplication. As a simplified example, see the code below (from DataModel.h/DataModel in my project):

#import <Foundation/Foundation.h>
#import "Element.h"

@interface DataModel : NSObject

@property (nonatomic) NSArray *elements;

@end

@implementation DataModel

@synthesize elements = _elements;

- (id)init {
    if (self= [super init]) {
        Element *element1 = [[Element alloc] init];
        element1.elementName = "first element";
        element1.elementNumber = "22";
        Element *element2 = [[Element alloc] init];
        element2.elementName = "second element";
        element2.elementNumber = "24";
        self.elements = [NSArray arrayWithObjects:element1, element2, nil];
    }
    return self;
}

@end

and this code (for Element.h/Element.m - the objects stored in the "elements" NSArray of the ViewController:

#import <Foundation/Foundation.h>

@interface Element : NSObject {

}

@property (nonatomic) NSString *elementName;
@property (nonatomic) NSString *elementNumber;

@end

#import "Element.h"

@implementation Element

@synthesize elementName = _elementName, elementNumber = _elementNumber;

@end

When the data model is it's own class, how do I make "elements" an accessible property in my sdef file? Do I need an object specifier in the DataModel or the Element class? NSApplication contains no properties, elements, or commands in this case.

Thanks!

matthewjselby
  • 112
  • 2
  • 8

0 Answers0