0

Can someone confirm my suspicion on this line of code.

NSUInteger newPath[] = {[indexPath section],0};

I'm pretty sure it's a C array of NSUIntegers. Am I right about this? Can you even make C arrays of Objective C objects?

Here is the code in context:

-(UITableViewCellEditingStyle)tableView:(UITableView *) tableViewEditingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{

if ([self isToManyRelationshipSection:[indexPath section]]) {
    NSUInteger newPath[] = {[indexPath section],0};
    NSIndexPath *row0IndexPath = [NSIndexPath indexPathWithIndexes:newPath length:2];

    NSString *rowKey = [rowKeys nestedObjectAtIndexPath:row0IndexPath];
    NSString *rowLabel = [rowLabels nestedObjectAtIndexPath:row0IndexPath];
    NSMutableSet *rowSet = [managedObject mutableSetValueForKey:rowKey];//!!!: to-many?
    NSArray *rowArray = [NSArray arrayByOrderingSet:rowSet byKey:rowLabel ascending:YES];

    if ([indexPath row] >= [rowArray count]) {
        return UITableViewCellEditingStyleInsert;
    }

    return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
aaronium112
  • 2,992
  • 4
  • 35
  • 50
  • 1
    NSUInteger isnt an object, its a c type, defined here: http://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/uid/20000018-SW71 – Richard J. Ross III Jan 13 '11 at 19:39
  • Nice, I didn't realize. So it's a dynamic basic type. "When building 32-bit applications, NSUInteger is a 32-bit unsigned integer. A 64-bit application treats NSUInteger as a 64-bit unsigned integer" – aaronium112 Jan 13 '11 at 23:40

3 Answers3

3

I'm pretty sure it's a C array of NSUIntegers. Am I right about this?

Yep, it sure is.

Can you even make C arrays of Objective C objects?

You can. For example, this is an array of two NSString *:

NSString *myStrings[] = {@"one", @"two"};

Is this useful? Sometimes, but it's almost always beneficial to use an NSArray if you need an array of objects.

mipadi
  • 398,885
  • 90
  • 523
  • 479
3

Yes, you're correct. However...

NSUInteger newPath[] = {[indexPath section],0};
NSIndexPath *row0IndexPath = [NSIndexPath indexPathWithIndexes:newPath length:2];

I would strongly discourage you from using this format to create an NSIndexPath that's intended for use in a UITableView. There's a convenience method to do this much more simply:

NSIndexPath *row0IndexPath = [NSIndexPath indexPathForRow:0 inSection:[indexPath section]];
Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
0

NSUInteger is not an Objective-c object. It is a typedef for an unsigned integer. Depending on your platform, it may be int or long. But it isn't an object. So you just have a c array of ints, basically.

GendoIkari
  • 11,734
  • 6
  • 62
  • 104