• 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: OT: Categories and alloc.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OT: Categories and alloc.


  • Subject: Re: OT: Categories and alloc.
  • From: mmalcolm crawford <email@hidden>
  • Date: Sat, 29 Jun 2002 21:42:59 -0700

On Friday, June 28, 2002, at 01:20 PM, Michael Gersten wrote:

The problem: Objective C and Java both allow protocols/interfaces to specify what you can do with an object. Anything that is written to an interface specification will work with any object that implements that specification, and can work with any class that does so.

But how does it get something of that interface type?

You must create an instance of a specific class. Protocols and interfaces simply define a collection of methods. They do not specify anything else, such as the implementation of the methods, instance variables the object might have, what superclasses the object might have etc.

You can declare a variable as being of type a given protocol/interface:

NSCoding *myCodableObject;

But it has occurred to me that even if you had all that, you'd still have a problem. Allocation.

As implied above, you must create an instance of a class that conforms to the relevant protocol / implements the relevant interface:

myCodableObject = [[NSMutableSet alloc] init];
or
myCodableObject = [[NSString alloc] initWithCString:"hello"];
or
myCodableObject = [NSDate date];
etc.

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Cocoa Programming...
  • Next by Date: Re: Making a window non-draggable
  • Previous by thread: Re: OT: Categories and alloc.
  • Next by thread: Re: Notifications and Threads
  • Index(es):
    • Date
    • Thread