Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Two classes in my suite be backed up by the same Cocoa class?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two classes in my suite be backed up by the same Cocoa class?



On Feb 26, 2010, at 4:52, Michael Zornek wrote:

> I've started to implement scriptability in my application. From a user
> perspective the app contains businesses which contain clients which contain
> todos, invoices, etc.
>
> Internally I model businesses and clients using the same class, CBCompany,
> and have a special flag that marks the company as a business or client.
>
> Current sdef file online at:
>
> http://media.clickablebliss.com/temp/ProfitTrain.sdef.zip
>
> My question, am I allowed to have two classes in my suite be backed up by
> the same Cocoa class? So far it seems to work up to a point. For example
> right now when I try to run this script I get an error when I try to set the
> company name of newClient.
>
> tell application "ProfitTrain"
>    set newBusiness to make new business
>    set newBusinessName to "NB " & time string of (current date)
>    set company name of newBusiness to newBusinessName -- this works
>    if company name of newBusiness is not newBusinessName then
>        display dialog "business name did not appear to be set"
>    end if
>
>    tell newBusiness
>        set newClient to make new client
>        set company name of newClient to "test" -- error here
>        if company name of newClient is not newClientName then
>            display dialog "client name did not appear to be set"
>        end if
>    end tell
>
>    delete newBusiness
> end tell
>
> The console error:
>
> 2010-02-25 22:36:53.056 ProfitTrain[4640:10b] Error converting apple event
> to script command: -1728
> 2010-02-25 22:36:53.057 ProfitTrain[4640:10b]     Original event:
> <NSAppleEventDescriptor: 'core'\'setd'{ 'data':'utxt'("test"), '----':'obj
> '{ 'form':'prop', 'want':'prop', 'seld':'bcON', 'from':'obj '{ 'form':'ID
> ', 'want':'cLNT', 'seld':'utxt'("B7BB0417-FB07-48D2-BE66-A81978048F2C"),
> 'from':'obj '{ 'form':'ID  ', 'want':'bISN',
> 'seld':'utxt'("65180F9E-2C0B-416D-A4A0-2EC133DF3C82"), 'from':'null'() } }
> }, &'csig':65536 }>
> 2010-02-25 22:36:53.057 ProfitTrain[4640:10b]     Offending object
> descriptor: <NSAppleEventDescriptor: 'obj '{ 'form':'prop', 'want':'prop',
> 'seld':'bcON', 'from':'obj '{ 'form':'ID  ', 'want':'cLNT',
> 'seld':'utxt'("B7BB0417-FB07-48D2-BE66-A81978048F2C"), 'from':'obj '{
> 'form':'ID  ', 'want':'bISN',
> 'seld':'utxt'("65180F9E-2C0B-416D-A4A0-2EC133DF3C82"), 'from':'null'() } }
> }>
>
> The four-character code for the company name property in that AppleEvent
> seems to be 'bcON' when I think should be 'ccON'. (b is for business c is
> for client, cON is for company name)
>
> Any kind of suggestions are welcome. I'm pretty much an AppleScript noob and
> am lucky I got this far. Thanks in advance.
>
> ~ Mike
> --
> Michael Zornek
> Clickable Bliss
> http://clickablebliss.com/

In principle it is possible to use the same Cocoa class for different scripting classes. I am not sure whether it can lead to problems though, as Cocoa Scripting does not always treat this properly. For instance, the NSScriptClassDescription API implicitly assumes that there is at most one scripting class for each Cocoa class, think of methods like +classDescriptionForClass:, that are used by Cocoa scripting. So I would definitely recommend you NOT to do this. Quite frankly, I would even expect this to be better design from a Cocoa perspective as well. Anyway, I think your current solution is definitely not the right way.

As I see it, I think you have two possibilities. Either the two classes are completely equivalent in the API they offer. In that case it makes sense to use the same Cocoa class, but you should make the scripting client class inherit from the scripting business class (and you don't need to declare anything else in the client class.) If the APIs are not exactly the same, it makes more sense to make the CBClient class a subclass of the CBCompany class, and for the scripting classes you may also use inherit as well.

Anyway, the problem you see has nothing to do with the overlapping Cocoa class. The problem is that you use /different/ codes for /the same/ property name. You should NEVER do that. Read TN2106 (which is essentially required reading BEFORE coming to this list IMHO!) Anyway, when you use inheritance you son't have that problem, at least not for your custom properties. This also applies to the property you call "uuid": the "ID  " code is used for the "id" property, and ONLY the "id" property.

Another thing is that when you target at least 10.5, you should use class-extension instead of class for your suite's application.

Christiaan

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

This email sent to email@hidden

References: 
 >Two classes in my suite be backed up by the same Cocoa class? (From: Michael Zornek <email@hidden>)



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.