Re: Difference between NSPoint, NSSize, NSRect and the CG Versions
On Aug 31, 2017, at 04:12 , Dave <dave@...> wrote:
There are “really” four different SDKs:
— 32-bit macOS
— 64-bit macOS
— 32-bit iOS
— 64-bit iOS
They are different in the sense that certain basic C types (such as int and float) are potentially different byte sizes, and certain derived Obj-C types (such as CGFloat, NSInteger and NSUInteger) are based on different C types (which may or may not affect their size).
In all SDKs other than 32-bit macOS, the NS and CG variants of points, rects, etc are synonyms, and can be used interchangeably.
In the 32-bit macOS SDK, they are based on different underlying types. Even if the struct members are the same size (they are, IIRC, all 4 bytes), the difference in type means the NS and CG versions are not technically compatible at the ABI level — at the calling interface between functions, for example.
Somewhere around macOS 10.5, when 64-bit macOS was introduced, it also became possible to compile 32-bit apps with a “compile like 64-bit” setting, which brought the 32-bit SDK in line with all the rest, and made the NS and CG types compatible. However, you had to opt into that manually, because using that option would make your code ABI-incompatible with (say) existing 3rd party frameworks that didn’t use the option.
In short, there are two sets (as Jens said) for historical reasons.
Apple seems to have settled on the CG versions as the new normal, so you should always use those in new code, except in the rare case where you’re writing an app that needs to deployable on old 32-bit only Macs. IIRC, Macs running 10.6.8 or higher have full 64-bit support, and again IIRC current macOS versions don’t support 32-bit code at all.