• 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
checking if an object's instance exists.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

checking if an object's instance exists.


  • Subject: checking if an object's instance exists.
  • From: Aaron Boothello <email@hidden>
  • Date: Sat, 05 Feb 2005 13:45:45 +0800

I've subclasses NSObject for  a custom class by the name of 'myObject'.
An instance of 'myObject' is called 'object1'.

I allocate memory and initialize the instance like this:
object1 = [[myObject alloc]init];

And release it like this:
[object1 release];

At one point in my code, i need to access the instance, but it could happen that the object hasnt been allocated or initialized. how do i check ?
my block of code looks something liek this:

-(void)method1
{
   [release object1];
   [self method2];
}

-(void)method2
{
int x;

if(object1)
     x=[object1 length];
}

but it dosent seem to work.
basically i need to check if the instance object1 exists or not.
Any suggestions ?

Cheers,
Aaron
 _______________________________________________
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

  • Follow-Ups:
    • Re: checking if an object's instance exists.
      • From: Kevin Ballard <email@hidden>
  • Prev by Date: NSCoding question regarding BOOL
  • Next by Date: Re: NSCoding question regarding BOOL
  • Previous by thread: Re: NSCoding question regarding BOOL
  • Next by thread: Re: checking if an object's instance exists.
  • Index(es):
    • Date
    • Thread