objective-ctype-conversioncore-foundationnsintegertoll-free-bridging

Converting CFIndex to NSInteger


This question is similar to mine, but does not contain an answer. I want to convert a CFIndex into an NSInteger. I have checked the list of types that have toll-free bridging and this is not one of them.


Solution

  • The concept of toll-free bridging only applies to Objective-C objects and Core Foundation objects. CFIndex is simply a typedef for the primitive signed long type, and NSInteger is a typedef for the primitive long type, which is the same as signed long. You can just assign a value of one type to a variable of the other type.