Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come NSRect and CGRect are incompatible types?

Ok , I'm consfused about an error :

error: incompatible type for argument 1 of 'initWithFrame:'

This is what causes it:

operationLabel = [[NSTextField alloc] initWithFrame:CGRectMake(0, self.frame.size.height / 2 - (40 * 3), self.frame.size.width, 100)];

The definition is:

- (id)initWithFrame:(NSRect)frameRect;

So the first argument is NSRect, lets check it :

typedef CGRect NSRect;

How can it cause an error? They are same types named differently!

like image 788
Kristina Brooks Avatar asked Aug 21 '10 17:08

Kristina Brooks


2 Answers

In addition to zoul's answer I thought I'd mention the two helper functions (macros?) by Apple (starting with 10.5):

NSRect NSRectFromCGRect(CGRect cgrect)
CGRect NSRectToCGRect(NSRect nsrect)
like image 168
Eiko Avatar answered Sep 21 '22 12:09

Eiko


NSRect is the same type as CGRect if building for iOS, for a 64-bit Mac architecture, or a 32-bit Mac architecture with the macro NS_BUILD_32_LIKE_64 is defined as 1 at the command line or in a prefix header.

Or, to quote NSGeometry.h:

#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
like image 41
Jens Ayton Avatar answered Sep 21 '22 12:09

Jens Ayton