• 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:Can't cram an NSRange into an NSArray?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re:Can't cram an NSRange into an NSArray?


  • Subject: re:Can't cram an NSRange into an NSArray?
  • From: Kirk Kerekes <email@hidden>
  • Date: Wed, 19 Jun 2002 16:10:27 -0500

Finally, I can answer somebody _else_'s question:

to create an object containing an NSRange:

NSValue * rangeInAnNSValue = [NSValue valueWithRange:(NSRange) aRange]

and to extract it:

NSRange aRange = [rangeInAnNSValue rangeValue];

Note that NSValue also has convenience routines for NSPoint, NSRect and NSSize, as well as pointers and other "obj-cTypes". See the docs on NSValue for details.

It is the intended container for these types.

Admittedly, using NSStringFromRange and NSRangeFromString make for easier debugging, but NSValue is probably quicker.

On Wednesday, June 19, 2002, at 03:14 PM, email@hidden wrote:

From: "James Winetke" <email@hidden>
To: email@hidden
Subject: Can't cram an NSRange into an NSArray?
Date: Wed, 19 Jun 2002 19:27:42 +0000

Hi. I'm slowly coming up to speed with the slightly twisty relationship
between Cocoa and C (at least from a perspective of one who doesn't
know C very well yet.) My current problem:

NSRange myRange;
NSMutableArray *myArray;

myRange = NSMakeRange(0,119);
myArray = [[NSMutableArray alloc] init];
[myArray addObject: myRange];

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.

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?

Thanks for any advice.

Jim
_______________________________________________
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.

  • Follow-Ups:
    • Re: Can't cram an NSRange into an NSArray?
      • From: Charles Jolley <email@hidden>
  • Prev by Date: Re: Can't cram an NSRange into an NSArray?
  • Next by Date: Re: Can't cram an NSRange into an NSArray?
  • Previous by thread: Re: Can't cram an NSRange into an NSArray?
  • Next by thread: Re: Can't cram an NSRange into an NSArray?
  • Index(es):
    • Date
    • Thread