In my Objective-C class's .h file, I have created a Category for NSIndexPath like this:
@interface NSIndexPath (YVTableView)
@property (nonatomic, assign) NSInteger subRow;
@end
and in that class's .m file, I have implemented that like:
static void *SubRowObjectKey;
@implementation NSIndexPath (YVTableView)
@dynamic subRow;
- (NSInteger)subRow
{
id subRowObj = objc_getAssociatedObject(self, SubRowObjectKey);
return [subRowObj integerValue];
}
- (void)setSubRow:(NSInteger)subRow
{
id subRowObj = [NSNumber numberWithInteger:subRow];
objc_setAssociatedObject(self, SubRowObjectKey, subRowObj, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
Now, when I am accessing the subRow property of NSIndexPath in Swift 3 using IndexPath then its giving me error:
Value of type 'IndexPath' has no member 'subRow'
If I am trying to access it using type casting
let subIndexPath = indexPath as NSIndexPath
let subRowIndex = subIndexPath.subRow
its always returning me '0' as 'subRow' value. May be its because IndexPath is value type and NSIndexPath is reference type.
I have implemented UITableViewDelegate to my Custom Delegate using Objective-C and implemented it to Swift class but in Swift where I am implementing the Custom Delegate methods, I am facing this issue.
I also tried to use NSIndexPath instead of IndexPath in my Custom Delegate implementation (Swift code) but it was giving me the error "Type YVViewController does not conform to protocol, Candidate has non matching-type".
Here is my Custom Delegate declaration :
@protocol YVTableViewDelegate <UITableViewDelegate>
@required
- (UITableViewCell *)tableView:(SKSTableView *)tableView cellForSubRowAtIndexPath:(NSIndexPath *)indexPath;
@end
Its working perfectly fine with Swift 2.x but after migrating to Swift 3, I am facing this issue.
subRow
? I just tried your code and it worked ok for me. – Thanh Pham