+ [NSNumberWithUnsignedInteger Number:] Literal?

I know that I can do @3 instead of [NSNumber numberWithInt:3]
but what is literal for [NSNumber numberWithUnsignedInteger:3] ?

+4
source share
3 answers

Typecasting also works if you do not remember the correct literal.

 NSNumber* number = @((NSUInteger)3); 
+4
source

You can use @3U or @3UL (or use regular integer suffixes to change the type, for example @3ULL for unsigned long long ).

See this page for more information on NSNumber literals.

+8
source

@3UL will provide you with an NSNumber that clearly has the same width / signature as NSUInteger .

But ask yourself why you want this? Since 3 represent exactly all the numeric types in C / Objective-C 1 @3 gives you an object that behaves the same. Although the type of constant used is different, the object you get can be used the same way and can be unpacked using the same set of methods.

1 Good, good, except for types that represent only 1 bit, for example _Bool and int : 1 .

+2
source

Source: https://habr.com/ru/post/1433920/


All Articles