Oleg Gordiichuk Oleg Gordiichuk - 3 months ago 32
Objective-C Question

Incompatible operand types ('NSUInteger' (aka 'unsigned long') and 'id _Nullable')

I have an issue connected with assigning of the value to the NSUInteger:

self.selectedGroup = GroupType //It is 3 from enum

self.menuItemsPostion = @{[NSNumber numberWithInteger:GroupType]: @0, [NSNumber numberWithInteger:GroupTime]: @1};

NSUInteger itemToSelect = [self isCapturedEntriesContainClienst] ? 1 : self.menuItemsPostion[[NSNumber numberWithInteger:self.selectedGroup]]; // Incompatible operand types ('NSUInteger' (aka 'unsigned long') and 'id _Nullable')

I understand that method from

- (nullable id)objectForKey:(id)key;
can return nullable object and that is why is a problem.

I am interested how it is possible to solve this issue.

Hoa Hoa

You have to get integerValue of your object in order to assign to your itemToSelect which is NSUInteger.

NSUInteger itemToSelect = [self isCapturedEntriesContainClienst] ? 1 : [self.menuItemsPostion[[NSNumber numberWithInteger:self.selectedGroup]] integerValue];