RE : a newbie question
RE : a newbie question
- Subject: RE : a newbie question
- From: Etienne Guérard <email@hidden>
- Date: Tue, 11 Nov 2008 12:21:39 -0500
- Thread-topic: a newbie question
You should derive your classes from NSObject, not from Object.
You normally don't have to #include <objc/Object.h>.
Where did you find such an example?
The alloc method basically does a calloc of the appropriate instance size.
The init method of NSObject does nothing.
It's good practive to always call an init metod in your own constructor and when you create a new object.
So all you have to do is this:
Fraction *myFraction = [[Fraction alloc] init];
Don't forget to (auto)release this object when you're done.
-------- Message d'origine--------
I am working from one of the numerous books in Obj C.
My question, which I have asked at another list, is about the method
init.
Firstly, here is the code, stripped somewhat of irrelevant
( hopefully ) code.
<<<<<<<<
/* #import <Foundation/Foundation.h> */
#import <stdio.h>
#import <objc/Object.h>
@interface Fraction : Object
{
int Numerator;
int Denominator;
}
-() methodsToImplementFraction;
@end
@implementation Fraction;
- ( void) methods{
doStuffHere;
}
@end
int main (int argc, const char * argv[]) {
Fraction *myFraction;
myFraction= [Fraction alloc];
myFraction= [Fraction init]; /* ??? */
return 0;
}
>>>>>>>>>
My question is this. As I step through the debugger in Xcode, it is
not that obvious that any change occurs with the code marked /* ???
*/. So, my question is , is there some fundamental thing that "init"
does ( for example, the member variables seem to be initialized with
the alloc method) ....and it obviously does...else it would not be
emphasized as much as it is...or will this become obvious later as I
work through more Obj-C.
Thanks in advance.
------------------------------------------------------------
This message and any attachments (the "message") are confidential and intended solely for the addressee(s). Any unauthorised use or dissemination is prohibited. E-mails are susceptible to alteration. Neither DxO Labs nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or falsified.
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et etablis a l'intention exclusive de ses destinataires. Toute utilisation ou diffusion non autorisee est interdite. Tout message electronique est susceptible d'alteration. DxO Labs et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, modifie ou falsifie.
_______________________________________________
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