Re: Can't cram an NSRange into an NSArray?
Re: Can't cram an NSRange into an NSArray?
- Subject: Re: Can't cram an NSRange into an NSArray?
- From: John Anderson <email@hidden>
- Date: Wed, 19 Jun 2002 13:05:53 -0700
The only problem that I see with this is that NSArray auto-retains your
objects, and an NSRange, being a C struct, will only exist as long as
your function exists. Perhaps you should try creating a custom object,
like MyRange. Then create a class method that creates one of your
objects with an array and autoreleases it, and create an instance
method that gets an NSArray back out.
John
On Wednesday, June 19, 2002, at 12:42 PM, Carl Jochen Norum wrote:
Quoting James Winetke <email@hidden>:
This doesn't work, because of "incompatible type for argument 1" on
that last line. It looks to me like I can only put Objective-C objects
in NS(Mutable)Arrays; I get similar warnings, though not errors, when
I
try to put an int in one.
That's correct - you can only store pointers in an NSArray.
With ints I can wrap them in an NSNumber at some unknown cost in
performance, but with NSRanges I'm sort of stuck. I hope to heck I
don't have to resort to stashing pairs of NSNumbers instead of
storing nice clean NSRanges. I don't even know how I'd do that
cleanly. Arrays of 2-item arrays?
Try:
NSArray *myArray = [[NSMutableArray alloc] initWithCapacity:10];
NSRange aRange = NSMakeRange(10,20);
[myArray addObject:&aRange];
Note - I haven't tried to compile this, so I have no idea if it works.
It's
really just a guess, and I have no doubt that someone will have a real
answer shortly.
--
Carl J Norum
4th Year Electrical Engineering/Computer Science Student
University of Saskatchewan
Saskatoon, Canada
_______________________________________________
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.
_______________________________________________
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.