3

How do you print out a UITables indexPath.row in the console window. I dont want to add NSLogs everywhere.

I keep getting 'is not a member' or property.

(lldb) expr (int) printf("%d \n",self.lastChangedIndexPath->_row)
error: 'NSIndexPath' does not have a member named '_row'


(lldb) print self.lastChangedIndexPath->_row
error: 'NSIndexPath' does not have a member named '_row'


(lldb) print self.lastChangedIndexPath->row
error: 'NSIndexPath' does not have a member named 'row'


(lldb) print self.lastChangedIndexPath.row
error: property 'row' not found on object of type 'NSIndexPath *'


(lldb) po  self.lastChangedIndexPath.row
error: property 'row' not found on object of type 'NSIndexPath *'

I think because row and section are in a UITableView category:

@interface NSIndexPath (UITableView)

+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;

@property(nonatomic,readonly) NSInteger section;
@property(nonatomic,readonly) NSInteger row;

@end

I even created a mini test app and created a clone of NSIndexPath called MyIndexPath and I can access it ok using:

(lldb) print self.indexPath->_row
(NSInteger) $0 = 10
(lldb) print self.indexPath.row
(NSInteger) $1 = 10
(lldb) 

TEST app

#import "ViewController.h"    



#pragma mark -
#pragma mark CLONE OF NSIndexPath ===================================
#pragma mark -
//------ a clone on NSindexPath with same section and row properties
@interface MyIndexPath : NSObject
@property(nonatomic) NSInteger section;
@property(nonatomic) NSInteger row;

@end
@implementation MyIndexPath
@end



#pragma mark -
#pragma mark MAIN CLASS that has MyIndexPath as iVar =============================
#pragma mark -

@interface ViewController (){
    NSString * _iVarString;
    int        _iVarInt;

}
@property (nonatomic, retain) NSString  * propertyString;
@property (nonatomic        ) NSInteger   propertyInt;
@property (nonatomic, retain) MyIndexPath * indexPath;
@end


@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Set iVars
    _iVarString = @"hello ivar";
    _iVarInt = 34;

    //Set properties (and synthesized ivars _propertyString and _propertyInt)
    self.propertyString = @"my propertyString";
    self.propertyInt    = 46;

    //Local vars
    NSString * localString_ = @"hello";
    int        localInt_    = 10;

    //------
    self.indexPath = [[MyIndexPath alloc]init];
    self.indexPath.section = 10;
    self.indexPath.row = 10;


    NSLog(@"PUT BREAKPOINT HERE");

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

And I can access it fine - just not in a UITableView category.

(lldb) print self.indexPath->_row
(NSInteger) $0 = 10
(lldb) print self.indexPath.row
(NSInteger) $1 = 10
(lldb) 

2 Answers 2

28

If lldb does not know about a property then you can always use the accessor function:

print (NSInteger) [self.lastChangedIndexPath row]
1
  • excellent... would help if I read the comment in the error. "cast the message send to the method's return type" Why doesnt print [self.lastChangedIndexPath row] work thats accessing the accessor too. Jun 14, 2013 at 15:03
13

You can make Xcode show the indexpath in the variables window by doubletapping on an nsindexpath variable and setting the following summary format:

section:{(int)[$VAR section]},row:{(int)[$VAR row]}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.