• 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: Referencing an instance variable in a class method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Referencing an instance variable in a class method


  • Subject: Re: Referencing an instance variable in a class method
  • From: Sarat Kongara <email@hidden>
  • Date: Wed, 6 Jul 2005 12:03:12 -0700

Hi Julio,
I guess you can create a static instance of the class and use it (kind
of a singleton).

static myClass *sharedInstance = nil;

+(void)myClassMethod:(NSString*)myPath {
     if(sharedInstance == nil)
       sharedInstance = [[myClass alloc] init];

     [[sharedInstance myTextView]
replaceCharactersInRange:NSMakeRange(0,[[[sharedInstance myTextView]
string] length]) withRTF:myData];
}

Regards
Sarat

On 7/6/05, Julio Cesar Silva dos Santos <email@hidden> wrote:
> I am trying to access an instance variable within a class method but
> I receive a warning: "instance variable accessed in class method". Is
> there a way to get around this warning? The code is something like this:
>
> @interface myClass : NSObject {
>    IBOutlet id myTextView;
> }
>
> +(void)myClassMethod:(NSString*)myPath;
> @end
>
> @implementation
> +(void)myClassMethod:(NSString*)myPath {
>    NSData * myData = [NSData dataWithContentsOfFile:myPath];
>    //Here pops up the warning
>    [myTextView replaceCharactersInRange:NSMakeRange(0,[[myTextView
> string] length]) withRTF:myData];
>    [myData release];
> }
> @end
>
> Why am I doing this? Because I am writing an application that uses
> AppleScript, but AS does not work fine with RTF files the way
> Objective-C does. Then I use the "call method" to (obviously) call a
> method inside a class but as far as I know this call only works for
> class methods, hence the myClassMethod declaration.
>
> Thanks for any help,
>
>
>
> Julio Cesar Santos
> email@hidden
> eMac 1GHz ComboDrive
> 640MB RAM
> Linux User #359973
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Referencing an instance variable in a class method (From: Julio Cesar Silva dos Santos <email@hidden>)

  • Prev by Date: Re: turning on the 'Open Recent' attribute for an NSMenuItem
  • Next by Date: Re: Referencing an instance variable in a class method
  • Previous by thread: Referencing an instance variable in a class method
  • Next by thread: Re: Referencing an instance variable in a class method
  • Index(es):
    • Date
    • Thread