Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit conversion of NSInteger error

Using MagicalRecord, I am trying to get the record with a particular clientNumber which is a NSInteger (defined as int16 as the data type).

This is my line of code where I'm getting the error:

ClientInfo *clientSelected = [ClientInfo MR_findFirstByAttribute:@"aClientNumber" withValue: clientNumber inContext:localContext];

UPDATE: This is the definition of MR_findFirstByAtytribute:

MR_findFirstByAttribute:(NSString *) withValue:(id)

This is the error I'm getting:

Implicit conversion of NSInteger (aka int) is disallowed with ARC

For the life of me, I don't see what's wrong. ClientInfo is defined as

@interface ClientInfo : NSManagedObject
like image 473
SpokaneDude Avatar asked Dec 19 '12 17:12

SpokaneDude


1 Answers

The parameter type for withValue is an id (a pointer). NSInteger is a scalar value (not an object) and cannot be converted to a pointer value implicitly.

This is purely a guess, but creating an NSNumber from the NSInteger might work:

NSNumber *val = [NSNumber numberWithInteger:clientNumber];
ClientInfo *clientSelected = [ClientInfo MR_findFirstByAttribute:@"aClientNumber" withValue:val inContext:localContext];
like image 147
mipadi Avatar answered Oct 12 '22 03:10

mipadi