• 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: help with NSCopying
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with NSCopying


  • Subject: Re: help with NSCopying
  • From: Greg Anderson <email@hidden>
  • Date: Sat, 11 Jan 2003 10:43:59 -0600

On Saturday, January 11, 2003, at 05:41 AM, Ted Lowery wrote:

How do I implement -copy for an object?

I have an object:

@interface ObjColorScheme : NSObject <NSCopying> {
NSColor* lineColor;
NSColor* fillColor;
BOOL showLine;
BOOL showFill;
}

then I provide a method in ObjColorScheme:

- (id)copyWithZone:(NSZone*)zone {
// what goes here?
}

I have a class of data for a day object that implements -copy, and I set it up like this:

- (id)initWithDOM:(int)inDay dataArray:(NSMutableArray *)inArray
{
self = [super init];

if (self) {
iDayOfMonth = inDay;
iDataArray = [inArray copy];
}

return self;
}

- (id)copyWithZone:(NSZone *)zone
{
DayData *copy = [[[self class] allocWithZone: zone] initWithDOM:iDayOfMonth dataArray:iDataArray];

return copy;
}


-copyWithZone just calls my secondary init function that takes initial values, and then returns the copy. As you might expect, the DayData class looks like:

@interface DayData : NSObject {
int iDayOfMonth;
NSMutableArray *iDataArray;
}

Substitute your favorite member variables and have at it.

Greg

---
Greg T. Anderson
Monkey Wrangler
http://homepage.mac.com/torgo
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Quickly drawing non-antialiased, discrete, pixels
  • Next by Date: Re: Module unlinking
  • Previous by thread: help with NSCopying
  • Next by thread: Finding the parent of an outline view item
  • Index(es):
    • Date
    • Thread