• 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: A simple Objective-C question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A simple Objective-C question


  • Subject: Re: A simple Objective-C question
  • From: Bill Bumgarner <email@hidden>
  • Date: Thu, 10 Apr 2008 11:41:13 -0700

On Apr 10, 2008, at 11:22 AM, Rama Krishna wrote:
I am new to Objective-C but I have done C++/C#/Java work. I have been doing
some experiments to understand how the language works. I found that it is
not necessary for an Objective-C class to derive from Object. I was able to
create a class which did not derive from Object contrary to my assumption
that all Objective-C classes implicitly derive from Object (such as in C# or
Java).


However, such a class has a problem. It cannot be allocated or initialized.
Because it can never get the alloc message as the alloc message is declared
in the Object class. My question ,therefore, is how can such classes be
instantiated. Is there a library function for that? Surely, the standard
alloc function must be using such a function. Or should I just derive all
classes from Object.

You need to implement said methods using lower level primitives available on the system (malloc(), for example)! And you'll likely need to implement a boatload of other methods, depending on what level of interoperability you want with the rest of Cocoa.


However, as someone else indicated...

... you probably do not want to create your own base class. If you look at Cocoa, you'll find that there are very very few base classes. NSProxy is about the most prominent one. Unless you really do need to create a new class hierarchy with very different semantics than the hierarchy derives from NSObject, there is no reason to do define a new root class.

NSObject (Not "Object", btw, as-- in the context of Cocoa-- that refers to pre-1992 APIs) presents a tremendous amount of functionality that provides the foundation on top of which much of Cocoa is implemented; KVO, KVC, bindings, allocation, reference counting, GC, etc.

b.bum


_______________________________________________

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


References: 
 >A simple Objective-C question (From: "Rama Krishna" <email@hidden>)

  • Prev by Date: re: NSTreeController Core Data Duplicate Entries Problem
  • Next by Date: Re: A simple Objective-C question
  • Previous by thread: Re: A simple Objective-C question
  • Next by thread: Re: A simple Objective-C question
  • Index(es):
    • Date
    • Thread