Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to assign NSUInteger to dictionary literal

Tags:

objective-c

I have

-(void)saveAsset:(NSUInteger) assetID 
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  NSDictionary *parameters = @{@"asset_id": assetID};

but get the following error:

Collection element of type 'NSUInteger' (aka 'unsigned long') is not an Objective-C object

How can I assign this? I have tried:

  NSDictionary *parameters = @{@"asset_id": [assetID integerValue]};

and

  NSDictionary *parameters = @{@"asset_id": (id)assetID};

but neither of them are working.

like image 254
timpone Avatar asked Nov 27 '25 22:11

timpone


1 Answers

@(assetID)

or (in old syntax):

[NSNumber numberWithInteger:assetID]

You tried to assign simple value (like int, char, etc.), while expected type is obj-c object (like NSNumber).

Btw. NSInteger is target depending type, so it will be 32-bit or 64-bit integer depending on target cpu.

like image 194
Rychu Avatar answered Nov 29 '25 15:11

Rychu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!