Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AussieNerd

macrumors newbie
Original poster
Mar 20, 2010
2
0
Could someone please explain why I can't make an integer by adding together the return values that are both integers themselves?

The range is a range that I have created from searching inside a string for a substring.

NSUInteger myInteger = [aRange location] + [aRange length];
 
Could someone please explain why I can't make an integer by adding together the return values that are both integers themselves?

The range is a range that I have created from searching inside a string for a substring.

NSUInteger myInteger = [aRange location] + [aRange length];

Try this:

NSUInteger myInteger = [aRange location];

Does it compile? If not, then the problem is not with the adding, it is somewhere else. Did you read the error messages the compiler gave you? What exactly did they say?
 
Could someone please explain why I can't make an integer by adding together the return values that are both integers themselves?

The range is a range that I have created from searching inside a string for a substring.

NSUInteger myInteger = [aRange location] + [aRange length];

If aRange is an NSRange, it's not an object; it's a C struct and [aRange location] *should* cause the compiler to howl in agony. Instead, you need to access the location and length fields using the standard C dot-notation:
Code:
aRange.location;
aRange.length;
 
If aRange is an NSRange, it's not an object; it's a C struct

Guiyon, you're a genius. Thanks. One of the most confusing thing about coming to iPhone development (or mac) is that it is a mash-up of different languages. Why not make it all work consistently? Could a range not be an object?
 
Guiyon, you're a genius. Thanks. One of the most confusing thing about coming to iPhone development (or mac) is that it is a mash-up of different languages. Why not make it all work consistently? Could a range not be an object?

it's certainly not a mash-up of different languages. Objective-C is it, you can mix C++ if you really want to. Objective-C is a superset of C, but that doesn't make it a mash-up in my mind.

NSRange is part of Foundation, which is a base framework providing C underpnnings and base classes. This provides low-level functionality. Foundation datatypes like this made it into Cocoa because they're already there, and serve the intended purpose. You could certainly have a range object, but it seems like overkill to me. What messages would you want a range to respond to? For simple pieces of data like this it seems better to me to have a structure, and not have to slow things down by incurring the overhead of an object, dealing with associated memory management, etc. when there aren't any real benefits.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.