Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
custom class init question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

custom class init question



Hello List,

I'm an experienced programmer, but new with Cocoa / Objective-C, and I have a question about initialization of objects.

Firstly, I'm developing a new class (subclass of NSObject), and trying to figure out what I'm supposed to put in an init method.  I'll obviously set initial values for instance variables and also invoke super init.

However, this leads me to the question of: What's the difference between these two NSString instances:

NSString *myString1 = @"some string";
NSString *myString2 = [[NSString alloc] initWithString: @"some string"];

I have seen either syntax in example codes.

So, I'm left to wonder if I should have my init method send an explicit alloc and init to each instance variable of my class (well, the ones that you can alloc and init anyway).

And what about release?  Should I create a release method that releases everything that I init?  Or how does autorelease behave on instance variables of an instantiated class?

I'm also having trouble finding the answers to questions like the above through search engines.  I've read LOTS of documentation on developer.apple.com and other sites.  I'm probably just not fluent enough in the terminology of Objective-C to perform the correct searches just yet.  Any pointers on where to look for "Experienced, but new to Cocoa / Objective-C" documentation?

Thanks for your time,

Kasey Speakman
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.