Re: Difference between NSPoint, NSSize, NSRect and the CG Versions


Dave
 

Thanks a lot Quincey and Jens for your through explanation - I had imported some Mac code from another project which uses NSRect’s and as my original project was iOS this caused compile errors, so rather than trying to handle both sets, I’ll just use the CG versions from now on.

There are a few calls to NSInsetRect, NSOffsetRect, etc., too, I’m guessing these can just be replaced with the CG version too.

Thanks again
All the Best
Dave


On 1 Sep 2017, at 01:11, Quincey Morris <quinceymorris@...> wrote:

On Aug 31, 2017, at 14:07 , Steve Christensen <punster@...> wrote:

Regarding NSPoint, I see it defined as

typedef CGPoint NSPoint;

so its x and y fields will be CGFloats.

Opening up a macOS project and looking at the definition of NSPoint, I see:

#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64

typedef CGPoint NSPoint;


#else

typedef struct _NSPoint {
    CGFloat x;
    CGFloat y;
} NSPoint;


#endif

So, it was the same size as CGPoint, but a different struct name, which was enough to create an ABI incompatibility. You could opt into the new typedef for 32-bit by using NS_BUILD_32_LIKE_64.



Join cocoa@apple-dev.groups.io to automatically receive all group messages.