Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Learning Cocoa differences
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Learning Cocoa differences



Make sure you're doing:

- (id) init
{
	self = [super init];  // rather than just [super init]

	//also, if you want any of the name, airports, etc. strings
	//to stick around, make sure to retain them.

	name = [@"" retain];
	airports = [@"" retain];
	airlines = [@"" retain];
	//etc...

	return self;
}

Then, if you're retaining your instance variables (which you should be, in most cases... Watch out for retain loops though...) you'll have to write a dealloc method too, so that you can release them. Otherwise, you get memory leaks. Bad thing.

- (void) dealloc //This will get called by the system when your object is no longer in use
{
[name release];
[airports release];
[airlines release];
//etc..
// And lastly, make sure you call dealloc on your superclass
[super dealloc];
}


I'm not sure what errors you're getting, but this will probably help a bunch.

For this stuff and more, check out stepwise, or specifically Malcolm Crawford's simple explanation here: http://www.stepwise.com/Articles/Technical/2001-03-11.01.html

Follow those rules, and you really can't go wrong.

-Jonah

On Wednesday, April 24, 2002, at 08:47  AM, Erick van Rijk wrote:

Why are there differences between the O'reilly book and the Examples found
on the O'reilly website. I get a lot of warnings when I follow the book....
Most of them are method not found warnings.
While I have declared them in the header file....


Any ideas?

Erick

Example:

- (id)init
{
    [super init];

    name = @"";
    airports = @"";
    airlines = @"";
    transportation = @"";
    hotels = @"";
    languages = @"";
    currencyName = @"";
    comments = @"";

    return self;
}

Book:
- (id)init
{
    [super init];

    [self setName:@""];
    [self setAirports:@""];
    [self setAirlines:@""];
    [self setTransportation:@""];
    [self setHotels:@""];
    [self setLanguages:@""];
    [self setCurrencyName:@""];
    [self setComments:@""];

    return self;
}
--
Did you know that:
No piece of paper can be folded more than 7 times.
_______________________________________________
studentdev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/studentdev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
studentdev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/studentdev
Do not post admin requests to the list. They will be ignored.

References: 
 >Learning Cocoa differences (From: Erick van Rijk <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.