I get warnings on them all.
Are you defining the handlers or relying on synthesized accessors from a property called objectVar? If the latter, they are only synthesized as instance methods.
I get warnings on them all.
Are you defining the handlers or relying on synthesized accessors from a property called objectVar? If the latter, they are only synthesized as instance methods.
I’ve played with this a bit, and I struggle to see the point. Strictly speaking any such handler should start with the AS equivalent of "self = [super init]"to initialize any instance variables in the superclass. But that’s not possible in AS. “[super init]” is equivalent to AS’s “continue init()”, but you can’t do the equivalent of "self = ".
You can leave this line out for subclasses of NSObject because there are no instance variables in the superclass to initialize, but it strikes me as potentially troublesome. It seems to me that we already have a way to initialize properties in AS, and we might as well use it and leave init to do any initialization of inherited properties/ivars.
But I’m open to persuasion on the issue…
Hmmm. How about this… Probably not a practical example, but let’s say we want to jazz up an NSButton in ASOC before sending it back to ObjC. NSButton inherits from a bunch of classes so it’s a good example of why you want to do a “self = [super init]” first. Who says our “on init()” in ASOC has to “return me”?.. Why not return a button you create? Not sure about using this in IB, but could be called with
NSButton *newFancyButton = [[myFancyButton alloc] init];
script myFancyButton
property parent : class "NSButton"
-- could just need to be NSObject, but seems that it
-- might help when returned so the calling method
-- doesn't bark about class type mis-match? Should
-- at least conform to
-- - (BOOL)isMemberOfClass:(Class)NSButton
on init()
set realButton to current application's class NSButton's alloc's init()
-- realButton has been through "self = [super init]" ???
tell realButton
-- psuedo code
-- many of these could differ for each instance
setButtonType_(aType)
setTitle_(aTitle)
setKeyEquivalent_(charCode)
setFont_(fontObject)
setAlignment_(mode)
-- etc, etc...
end tell
return realButton
-- instead of "return me"
end init
end script
Whatcha think?
Well, the only place the string “objectVar” shows up is (truncated code):
-- @interface ObjCClass : NSObject {
-(IBAction)setObjectVar:(id)sender;
-(IBAction)setObjectVarClass:(id)sender;
-- @implementation ObjCClass
-(IBAction)setObjectVar:(id)sender
[myASClass setObjectVar: @"New value to put into var by instance method"];
-(IBAction)setObjectVarClass:(id)sender
[[myASClass class] setObjectVar: @"New value to put into var by class method"];
-- script ASClass
on objectVar()
on setObjectVar_(tValue)
So it appears to me that it’s only because of the arg/parameter being used. Even set up a new set and go no warning, but moving on to more than one drew the same warning (unless I set up my ObjC code wrong… Newbie pains, you know?) :rolleyes:
Honestly? It scares me
No, I meant how are you using it in the AS class.
Heh. Well, I think I’ll let that one go for now and cross that bridge when I get to it. Got other things in mind that I wanted to mix the two for… At least until it starts bugging me.
In the most basic of tests…
property instanceVar : "Default Value"
on objectVar()
return my instanceVar
end objectVar
on setObjectVar_(tValue) -->> No error here in .m
set my instanceVar to tValue
end setObjectVar_
It gives the same error on:
on setObjectVar_andAnother_(tValue1, tValue2)
set my instanceVar to tValue1
set my instanceVar2 to tValue2
end setObjectVar_andAnother_
Other than that, all I do is some “log ” for testing so I can make sure things are doing what I hope they will.
FWIW, if you’d called your property objectVar, you wouldn’t have needed to write the first two accessors.
[Edit: See self realized correction in next post, too]
That worked for getting the value of the property from the instance, but failed getting it from the class:
property objectVar : "Default Value"
-- on objectVar() commented out
[myASClass objectVar];
returnString = Default Value
[[myASClass class] objectVar];
+[ASClass objectVar]: unrecognized selector sent to class 0x1028a05a0
setObjectVar seems to work on both instance and class, but I can’t verify a change in class because of that error.
Also, I started with the original setting (using a different name for the property) thinking of future reference where the value to be returned could end up being the result of a handler/function inside the ASClass instead of just a property. Now that I know this, however, I guess I can keep both in mind.
Next is to see what happens when creating a new instance of ASClass with alloc/init (secondASClass)… If I set the value in the class using setObjectVarClass before creating a new instance, what would be the expected behavior when running [secondASClass objectVar]? I’m still too new to Obj-C and ASOC to know… Should it return the original “Default Value” that’s defined in the ASClass, or should it return the new value set by setObjectVarClass ahead of time (until app restart, I presume)?
If the new instance takes on the “Default Value” then I don’t really see any point of setting it to anything else in the class object itself.
Ahhhh. I see. I just read through some more basic docs… I now see that I needed to comment out BOTH
– on objectVar()
– setObjectVar()
Ok. That’s working right… At least for instance settings. Fails for both of the class types.
Right – because a property is a type of instance variable.