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?
Do not use the getter/setter dot syntax, use brackets:
po (int)[index row]
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.
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.
po index.row
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.
You could try this, it works perfectly for me:
po (int)[indexPath row]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With