Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSIndexPath does not recognize item, section, or row as properties

When iOS 7.1 sends my viewController:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
    cellForItemAtIndexPath:(NSIndexPath *)indexPath

The indexPath object does not recognize the properties: item, section or row. The expected values are section = 0, item = 0

The Debugger shows:

**indexPath NSIndexPath *   0xc000000000000016

 NSObject       
_indexes    NSUInteger *    NULL    
  *_indexes     
_length     
_reserved   void *  NULL

The log reports:

(lldb) po indexPath
<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}
(lldb) po indexPath.item
error: property 'item' not found on object of type 'NSIndexPath *'
error: 1 errors parsing expression
(lldb) po indexPath.row
error: property 'row' not found on object of type 'NSIndexPath *'
error: 1 errors parsing expression
(lldb) po indexPath.section
error: property 'section' not found on object of type 'NSIndexPath *'
error: 1 errors parsing expression****

Any ideas why this is happening and what to do about it?

like image 427
Carl Carlson Avatar asked Jul 08 '14 01:07

Carl Carlson


3 Answers

Do not use the getter/setter dot syntax, use brackets:

  1. po (int)[index row]
  2. po (int)[index section]

Note that the (int) is necessary to print the row/section as an integer rather than a hex. Other such useful formatting parameters for LLDB can be found here.

EDIT

The Swift overlay to the Foundation framework provides the IndexPath structure, which bridges to the NSIndexPath class. The IndexPath value type offers the same functionality as the NSIndexPath reference type, and the two can be used interchangeably in Swift code that interacts with Objective-C APIs. This behavior is similar to how Swift bridges standard string, numeric, and collection types to their corresponding Foundation classes.

  1. po index.row
  2. po index.section

work as expected. The comment on p vs. po still stands.

It is worth noting that you may use IndexPath in Swift instead of NSIndexPath, as described in the Apple Documentation.

like image 196
SwiftArchitect Avatar answered Nov 08 '22 23:11

SwiftArchitect


You could try this, it works perfectly for me:

po (int)[indexPath row]
like image 45
benzford Avatar answered Nov 08 '22 22:11

benzford


Why are you using po? The resulting row and section of the NSIndexPath are NSUIntegers, or long ints, not objects.

While p means print, po means print object.

`NSIndexPath is an object. The contents of it aren't.

Use p, instead of po.

p [indexPath section]

p [indexPath row]

p indexPath.section

p indexPath.row

I make the same mistake all the time.


Note: If using a UIViewController and extending it to have a UITableViewController delegate and datasource, make sure to import UITableView.h or UIKit into your header file.

This file adds extensions to NSIndexPath so that you can use row and section. If you don't import the file that declares them, you will go mad wondering why indexpath.row and indexpath.section don't work.

If you want to access row and section of NSIndexPath outside of a UITableViewController, you will need to do those imports to get access to those extensions.

like image 2
Alex Zavatone Avatar answered Nov 08 '22 23:11

Alex Zavatone