• 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: What is the equivalent of a C++ pure-virtual function in Objective-C?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the equivalent of a C++ pure-virtual function in Objective-C?


  • Subject: Re: What is the equivalent of a C++ pure-virtual function in Objective-C?
  • From: Alex Curylo <email@hidden>
  • Date: Sun, 11 Jan 2009 18:46:20 -0800


On 11-Jan-09, at 6:32 PM, email@hidden wrote:

Still,
anyone wants to give me some guidance on protocols and how they should
be employed, I'm all ears (eyes).


Well, here's one I just employed. Define it like this

@protocol PAImageCollection <NSObject>

@required

- (int)collectionCount;
- (UINavigationController *)collectionController;
- (NSString *)fileForIndex:(int)collectionIndex;
- (BOOL)canRemove;

@end

and then any class you declare like this

@interface FavoritesTableViewCell : UITableViewCell <PAImageCollection>

will throw up a compile error if it doesn't match everything under @required in the protocol.

And to keep track of a derived instance as a variable/argument, something like

   id<PAImageCollection> collection;

does the trick.

That should pretty much cover any sane use of pure virtual functions you have in mind.

--
Alex Curylo -- email@hidden -- http://www.alexcurylo.com/

"I misjudged you Alex; you're a @#$%!!, but you're a consistent,
 smart $#@%^!!, and the kind of @$^#&$!! I can #$@*&!! respect."
    -- John G. Spragge

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: What is the equivalent of a C++ pure-virtual function in Objective-C?
  • Next by Date: NSMutableAttributedString, NSFontAttributeName, and reference counting
  • Previous by thread: Re: What is the equivalent of a C++ pure-virtual function in Objective-C?
  • Next by thread: NSMutableAttributedString, NSFontAttributeName, and reference counting
  • Index(es):
    • Date
    • Thread