How can I make an integer with id in iOS

My code looks something like this:

[request setPostValue:employee.empId forKey:@"empId"]; 

where employee is a "POCO" object that has the empId property, which is int, but the method expects an identifier.

I already tried sending setPostValue: & employee.empId and setPostValue: [employee.empId], but still getting errors.

Is it possible to get (id) in any way? or should I create another object from a property?

+8
ios objective-c
source share
2 answers

Yes, you need to create another object from the integer before you can pass it to a method waiting for id .

 [request setPostValue:[NSNumber numberWithInt:employee.empId] forKey:@"empId"]; 

Alternatively, with newer versions of the SDK (after iOS 6, I think?), You can use the new Objective-C box lists:

 [request setPostValue:@(employee.empId) forKey:@"empId"]; 
+25
source share
 [request setPostValue:[NSNumber numberWithInt:employee.empId] forKey:@"empId"]; 
+6
source share

All Articles