views:

23

answers:

2

I am surprised that the following calls result in type-cast warning:

I have a class MyClass with the following method:

- (id) initWithData:(NSUInteger)mNumber;

when I call this method using

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   MyClass *lClass = [[MyClass alloc] initWithData:indexPath.row];
   ...

I get a warning "Passing argument 1 of 'initWithData' makes pointer from integer without a cast".

When I typecast 'initWithData' like this:

MyClass *lClass = [[MyClass alloc] initWithData:(NSUInteger)indexPath.row];

the warning remains unchanged indicating I haven't addressed the cause of the message. Anyone knows where and why I am getting off the track?

+2  A: 

Try renaming -initWithData: to other names like -initWithRowNumber:. The compiler may be confusing it with -[NSData initWithData:] which takes an NSData* as input, not NSUInteger.

KennyTM
I agree. In particular, *alloc* 's return value is of type *id*. So it's not really type-safe.
Codo
I renamed it to initWithContent and the warning vanished ... Thank you
iFloh
+1  A: 

Renamem initWithData to something else.

Jordan