Carl Carlson Carl Carlson - 14 days ago 5
iOS Question

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?

Answer

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

  1. po [index row]
  2. po [index section]