Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Element "initializers"




On 13 Jul 2007, at 10:12 PM, Scott Thompson wrote:

I'm working on an AppleScript class for my application and I'd like to create some properties that can be defined when an instance of the class is created, but which are read-only afterward.

For example, the instances of the class include the "name" and "category" properties. These properties are defined when the instance is created, and can be read afterward, but there should not be any way to change those properties.

I'm curious about the right way to express that in the sdef and in the running application. I envision two scenarios:

1. I mark the properties as "read-only" in the sdef and require the user to specify the value of those properties in the "with properties" parameter of the "make" command. Can a read-only property still be initialized with the "with properties" parameter?


Yes: you can get the properties from [NSScriptCommand currentCommand] in -init.


2. I leave the properties read/write but just return an error if you try to set the value after the instance is created.


If they are normally read-only, it is better to flag them as such in the sdef. Note that this flag is only used for clarity to the user, and doers not have any real purpose.


Also you have to implement the setters, but you best leave them empty. Don't return an error, because they will be called right after init (in the implementation of NSCreateCommand).

Is either of these scenarios the preferred one? (or is there some other mechanism that would work better?)

Scott

So I would say the first one is the preferred one, and the second one would not even work.


An alternative is to use the "with data" argument, but that only works when your object can be created by coercing some standard data object.

hth,
Christiaan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/email@hidden

This email sent to email@hidden
References: 
 >Element "initializers" (From: Scott Thompson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.