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: Don Briggs <email@hidden>
- Date: Wed, 19 Jun 2002 12:56:31 -0700
Try
NSString *NSStringFromRange(NSRange aRange)
and put an NSString describing your range into the array.
The resulting string is a natural-born object, and NSArray
et al. can contain it.
The complement function is
NSRange NSRangeFromString(NSString *aString)
to recover the range.
Both are in
FoundationFunctions.html
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.