Friday, February 22, 2019

#1 2018-12-20 08:24:03 pm

technomorph
Member
Registered: 2017-12-14
Posts: 96

Property Classes

I notice a great deal in ObjC that there is always a class reference on the left side
of the property before the *property
when trying to emulate some ObjC example code into ASObjC I sometimes feel like
i'm not providing enough info, or that I'm leaving something out.

I started to think how could I do this and if I can declare something like:

Applescript:

property NSDictionary : a reference to current application's NSDictionary

why can't I do this:

Applescript:

property anEntry : a reference to current application's NSDictionary

I was worried that I might have an issue with referring to the class multiple times
but here is what I tried out and it worked:

Applescript:

use AppleScript version "2.4"
use framework "Foundation"

-- classes, constants, and enums used

property NSDictionary : a reference to current application's NSDictionary
property anEntry : a reference to current application's NSDictionary
property anBook : a reference to current application's NSDictionary


set newEntry to my makeNewEntryNamed:"Hello" withType:"test"
-- results -> (NSDictionary) {name:"Hello", type:"test"}
set newBook to my makeNewBookNamed:"ASObjC Explored" withAuthor:"Shane Stanley"
-- results -> (NSDictionary) {name:"ASObjC Explored",author:"Shane Stanley"}

on makeNewEntryNamed:aName withType:aType
   set newEntryObject to anEntry's dictionaryWithObjects:{aName, aType} forKeys:{"name", "type"}
end makeNewEntryNamed:withType:

on makeNewBookNamed:aName withAuthor:aAuthor
   set newEntryObject to anBook's dictionaryWithObjects:{aName, aAuthor} forKeys:{"name", "author"}
end makeNewBookNamed:withAuthor:

an thought's on this approach?

Offline

 

#2 2018-12-20 08:46:11 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5571

Re: Property Classes

technomorph wrote:

an thought's on this approach?



I might be misunderstanding what you're trying to achieve, but the result looks awfully like obscufation to me.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2018-12-21 06:37:42 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11550
Website

Re: Property Classes

I agree with Shane.

And rather than dictionaries I recommend to use custom classes.


regards

Stefan

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)