Convert NSInteger to NSUInteger?

前端 未结 4 855
天涯浪人
天涯浪人 2021-02-04 00:30

I am trying to convert a NSInteger to a NSUInteger and I googled it and found no real answer. How would I do this?

4条回答
  •  生来不讨喜
    2021-02-04 01:18

    NSInteger and NSUInteger are just typedefs for primitive integer types:

    #if __LP64__ || NS_BUILD_32_LIKE_64
      typedef long NSInteger;
      typedef unsigned long NSUInteger;
    #else
      typedef int NSInteger;
      typedef unsigned int NSUInteger;
    #endif
    

    As such, you don't need to "convert" between them. A simple cast should be sufficient. Like:

    NSInteger myInt = 0;
    NSUInteger unsignedInt = (NSUInteger)myInt;
    

提交回复
热议问题