• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: access property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: access property


  • Subject: Re: access property
  • From: Evan Schoffstall <email@hidden>
  • Date: Mon, 14 Nov 2011 11:43:32 -0500

Surely. There are two options in writing observations.
One, Observe all properties. Instead of adding an observer for each, a simple for loop and access to the Objective-C runtime should do the trick. http://stackoverflow.com/questions/1910449/observing-a-change-to-any-class-property-in-objective-c

Second, Observe specified properties: [self addObserver:self forKeyPath:@"myPrefsVal" options:NSKeyValueObservingOptionNew context:nil];

Implement that under awakeFromNib or init depending on your super type.

If implemented, every time that myPrefsVal changes a message will be sent to observeValueForKeyPath:ofObject:change:context 
which MUST be implemented by you

Add the below method--

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

{

    

}


To the observeValueForKeyPath method, you must here send myPrefsVal to whatever object you want.

All of the above is in Objective-C, you'll have to translate it into ASOC. 

I suggest you read up on Key-Value-Coding (KVC) as apple will answer all your questions under this documentation: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html

-- 
Evan Schoffstall
Sent with Sparrow

On Monday, November 14, 2011 at 11:12 AM, droom departement wrote:

Evan,

can you set me a little more in the "observer" direction ?
Or can you give me an url to an example ?


2011/11/14 Evan Schoffstall <email@hidden>
If you mean to say get a value every x seconds than okay..
Use NSTimer

If you mean to say you want to get the value of a property when it changes (which makes more sense)

Try adding an observer.

-- 
Evan Schoffstall
Sent with Sparrow

On Monday, November 14, 2011 at 10:07 AM, droom departement wrote:

No, I just like to get "from time to time" the value of a certain property.


2011/11/14 Evan Schoffstall <email@hidden>
Did you try something like

set myObject to dbViewController's new()
set myString to myObject's myPrefsVal

-- 
Evan Schoffstall
Sent with Sparrow

On Monday, November 14, 2011 at 9:02 AM, droom departement wrote:

How can I get the value of a property: myPrefs (declared in an objective-C class) from within an applescript class ?
the objective-C class:

@interface dbViewController : NSObject {
 NSString *myPrefsVal;
}
@property (nonatomic, retain) NSString *myPrefsVal;
...
@end

@implementation dbViewController
@synthesize myPrefsVal;
...
@end


_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)

This email sent to email@hidden





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

This email sent to email@hidden

References: 
 >access property (From: droom departement <email@hidden>)
 >Re: access property (From: Evan Schoffstall <email@hidden>)

  • Prev by Date: Re: access property
  • Next by Date: Reading Bundle versions string, short
  • Previous by thread: Re: access property
  • Next by thread: Reading Bundle versions string, short
  • Index(es):
    • Date
    • Thread